www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - version(D_Version2)

reply Derek Parnell <derek psych.ward> writes:
I just want to lodge a formal complaint. 

The implementation of version(D_Version2) that insists that code in its
scope must be valid version 1 (one) code is a true PITA.

<rant rating="venomous">
Almost without exception, I'm finding that I have to use the string mixin
idiom. Using that idiom excessively is bad coding form, IMNSHO.

Having to constantly use 

  version(D_Version2) {
     mixin(` ... version 2 specific code ... `);
  }

is NOT A GOOD SIGN !!!!

</rant>

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
Mar 12 2008
next sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Derek Parnell wrote:
 I just want to lodge a formal complaint. 
 
 The implementation of version(D_Version2) that insists that code in its
 scope must be valid version 1 (one) code is a true PITA.
 
 <rant rating="venomous">
 Almost without exception, I'm finding that I have to use the string mixin
 idiom. Using that idiom excessively is bad coding form, IMNSHO.
 
 Having to constantly use 
 
   version(D_Version2) {
      mixin(` ... version 2 specific code ... `);
   }
 
 is NOT A GOOD SIGN !!!!
 
 </rant>

I just resorted to this in something I was doing the other day:
 gcc -C -E -xc file_in.d | sed -e "s/^#/#line/" > file.d
 dmd file.d

It could solve your problem too. :-) --bb
Mar 12 2008
parent reply Derek Parnell <derek psych.ward> writes:
On Wed, 12 Mar 2008 17:56:49 +0900, Bill Baxter wrote:

 I just resorted to this in something I was doing the other day:
 
  > gcc -C -E -xc file_in.d | sed -e "s/^#/#line/" > file.d
  > dmd file.d

I have no idea what that means. I don't use gcc and I run D in a Windows environment. I use Linux daily at the office because that's I develop software for (but not in C/C++) so I understand the 'sed' part is, but what's gcc doing? -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Mar 12 2008
next sibling parent reply Alexander Panek <alexander.panek brainsware.org> writes:
Derek Parnell wrote:
 On Wed, 12 Mar 2008 17:56:49 +0900, Bill Baxter wrote:
 
 I just resorted to this in something I was doing the other day:

  > gcc -C -E -xc file_in.d | sed -e "s/^#/#line/" > file.d
  > dmd file.d

I have no idea what that means. I don't use gcc and I run D in a Windows environment. I use Linux daily at the office because that's I develop software for (but not in C/C++) so I understand the 'sed' part is, but what's gcc doing?

Preprocessing, probably?
Mar 12 2008
parent reply Gregor Richards <Richards codu.org> writes:
Alexander Panek wrote:
 Derek Parnell wrote:
 On Wed, 12 Mar 2008 17:56:49 +0900, Bill Baxter wrote:

 I just resorted to this in something I was doing the other day:

  > gcc -C -E -xc file_in.d | sed -e "s/^#/#line/" > file.d
  > dmd file.d

I have no idea what that means. I don't use gcc and I run D in a Windows environment. I use Linux daily at the office because that's I develop software for (but not in C/C++) so I understand the 'sed' part is, but what's gcc doing?

Preprocessing, probably?

Yeah, this is the "simple" way of using the C preprocessor with any language. - Gregor Richards
Mar 12 2008
next sibling parent reply JMNorris <nospam nospam.com> writes:
Gregor Richards <Richards codu.org> wrote in
news:47D8017C.6000003 codu.org: 

 Alexander Panek wrote:
 Preprocessing, probably?

Yeah, this is the "simple" way of using the C preprocessor with any language. - Gregor Richards

Maybe someone should write a preprocessor for D, as horrifying as the thought may be to some. It should: 1. Be usable only for conditional compilation. No constants allowed outside preprocessing directives and no pseudo-function macros at all. 2. (Perhaps) work on *.dpp files and generate *.d files. D's conditional compilation works fine *except* across versions with varying syntaxes (such as D1 and D2). If D becomes popular enough to support multiple competing commercial compilers, then compiler-specific syntax extensions, syntax bugs, and other syntax hiccups will exacerbate the problem. We can keep within 98% of the spirit of Walter's (and mine, for that matter) anti-preprocessing bias by keeping defines and D code absolutely segregated. -- JMNorris
Mar 12 2008
parent Gregor Richards <Richards codu.org> writes:
JMNorris wrote:
 Gregor Richards <Richards codu.org> wrote in
 news:47D8017C.6000003 codu.org: 
 
 Alexander Panek wrote:
 Preprocessing, probably?

language. - Gregor Richards

Maybe someone should write a preprocessor for D, as horrifying as the thought may be to some. It should: 1. Be usable only for conditional compilation. No constants allowed outside preprocessing directives and no pseudo-function macros at all. 2. (Perhaps) work on *.dpp files and generate *.d files. D's conditional compilation works fine *except* across versions with varying syntaxes (such as D1 and D2). If D becomes popular enough to support multiple competing commercial compilers, then compiler-specific syntax extensions, syntax bugs, and other syntax hiccups will exacerbate the problem. We can keep within 98% of the spirit of Walter's (and mine, for that matter) anti-preprocessing bias by keeping defines and D code absolutely segregated.

I've considered adding preproc support to DSSS for situations like this one, but I also have the anti-preprocessing bias, and I'm afraid of what the backlash might be like. Still, there are rare situations (e.g. this one) where preprocessing is hard to avoid. - Gregor Richards
Mar 12 2008
prev sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Scott S. McCoy wrote:
 You could always just call cpp(1) directly.
 
 I do this with various excessively for awk.

I wondered if that was the case, but in my cygwin terminal cpp --help gave me the help for gcc. At that point I just decided calling gcc -E was less likely to be problematic. --bb
Mar 13 2008
prev sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Derek Parnell wrote:
 On Wed, 12 Mar 2008 17:56:49 +0900, Bill Baxter wrote:
 
 I just resorted to this in something I was doing the other day:

  > gcc -C -E -xc file_in.d | sed -e "s/^#/#line/" > file.d
  > dmd file.d

I have no idea what that means. I don't use gcc and I run D in a Windows environment. I use Linux daily at the office because that's I develop software for (but not in C/C++) so I understand the 'sed' part is, but what's gcc doing?

It's what the others said. gcc -E just runs the preprocessor -C says to keep the comments instead of stripping them -xc says to pretend the following file is C code despite the extension. The preprocessor spits out line directives like # 1 "somefile" In D those are supposed to be #line 1 "somefile" So the sed thing makes that change. The regexp there is pretty dumb, though. Really I guess you need a parser that can understand quoted strings to do the job 100% properly. But it was enough for my case. --bb
Mar 12 2008
prev sibling parent "Scott S. McCoy" <tag cpan.org> writes:
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

You could always just call cpp(1) directly.

I do this with various excessively for awk.

On Wed, 2008-03-12 at 09:14 -0700, Gregor Richards wrote:

 Alexander Panek wrote:
 Derek Parnell wrote:
 On Wed, 12 Mar 2008 17:56:49 +0900, Bill Baxter wrote:

 I just resorted to this in something I was doing the other day:

  > gcc -C -E -xc file_in.d | sed -e "s/^#/#line/" > file.d
  > dmd file.d

I have no idea what that means. I don't use gcc and I run D in a Windows environment. I use Linux daily at the office because that's I develop software for (but not in C/C++) so I understand the 'sed' part is, but what's gcc doing?

Preprocessing, probably?

Yeah, this is the "simple" way of using the C preprocessor with any language. - Gregor Richards

Mar 12 2008