www.digitalmars.com         C & C++   DMDScript  

D - Conditional compilation

reply "Walter" <walter digitalmars.com> writes:
I posted some new specs on conditional compilation at:

    www.digitalmars.com/d/attribute.html
Dec 02 2001
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
Looks better.  I think you should allow debug and version attributes to
contain not only declarations, but also statements, if at a scope where
statements are allowed.  I don't want to have to make a whole 'nother copy
of a function just to be able to change one statement inside for a
particular version.

Also I think someone could get into lots of trouble using the   version (
whatever ) :   form of the AttributeElse, especially at module scope.  Is
there a way to go back to the "normal" version, such as   version :   ?

I'd much rather require use of  {  }  instead of allowing one to use  :  to
specify an attribute for anything which follows.  Too easy to forget to
close those off.

Sean


"Walter" <walter digitalmars.com> wrote in message
news:9uctpi$2rvp$1 digitaldaemon.com...
 I posted some new specs on conditional compilation at:

     www.digitalmars.com/d/attribute.html
Dec 02 2001
parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:9ud0fr$2upb$1 digitaldaemon.com...
 Looks better.  I think you should allow debug and version attributes to
 contain not only declarations, but also statements, if at a scope where
 statements are allowed.  I don't want to have to make a whole 'nother copy
 of a function just to be able to change one statement inside for a
 particular version.
The version statement is the analogous syntax to enclose statements. There are no version expressions, however <g>.
 Also I think someone could get into lots of trouble using the   version (
 whatever ) :   form of the AttributeElse, especially at module scope.  Is
 there a way to go back to the "normal" version, such as   version :   ?
 I'd much rather require use of  {  }  instead of allowing one to use  :
to
 specify an attribute for anything which follows.  Too easy to forget to
 close those off.
That's done to be consistent with all the other attributes.
Dec 02 2001
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
Ahhh.. I see what you're doing.  Are there any other places where a version
would be nice to have?  I can think of a few:

Formal parameter list
Array initializer list

If it's to replace macro-style conditional compilation, you should be able
to use version or debug just about anywhere it can possibly be parsed
properly.  I'd *really* like to be able to version a function signature
without having to duplicate the entire function body.

On a semi-related note, can we define our own attributes?  For instance if I
wanted to switch a whole lot of functions from one calling convention to
another, I'd like to do this:

version (cdecl_sig)
{
  attribute mycall = cdecl;
}
version (stdcall_sig)
{
  attribute mycall = stdcall;
}

attribute mycall void myfunc(int a)
{
}

attribute mycall void myfunc2(int a)
{
}

attribute mycall void myfunc3(int a)
{
}

Rather than have to version each function separately, with its associated
duplication of function bodies.

Sean


"Walter" <walter digitalmars.com> wrote in message
news:9udncu$lfn$1 digitaldaemon.com...
 "Sean L. Palmer" <spalmer iname.com> wrote in message
 news:9ud0fr$2upb$1 digitaldaemon.com...
 Looks better.  I think you should allow debug and version attributes to
 contain not only declarations, but also statements, if at a scope where
 statements are allowed.  I don't want to have to make a whole 'nother
copy
 of a function just to be able to change one statement inside for a
 particular version.
The version statement is the analogous syntax to enclose statements. There are no version expressions, however <g>.
 Also I think someone could get into lots of trouble using the   version
(
 whatever ) :   form of the AttributeElse, especially at module scope.
Is
 there a way to go back to the "normal" version, such as   version :   ?
 I'd much rather require use of  {  }  instead of allowing one to use  :
to
 specify an attribute for anything which follows.  Too easy to forget to
 close those off.
That's done to be consistent with all the other attributes.
Dec 02 2001
parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:9ue60n$13ps$1 digitaldaemon.com...
 Ahhh.. I see what you're doing.  Are there any other places where a
version
 would be nice to have?  I can think of a few:

 Formal parameter list
I think this can be avoided by overloading with a version'd function.
 Array initializer list
You have me there.
 If it's to replace macro-style conditional compilation, you should be able
 to use version or debug just about anywhere it can possibly be parsed
 properly.  I'd *really* like to be able to version a function signature
 without having to duplicate the entire function body.

 On a semi-related note, can we define our own attributes?  For instance if
I
 wanted to switch a whole lot of functions from one calling convention to
 another, I'd like to do this:

 version (cdecl_sig)
 {
   attribute mycall = cdecl;
 }
 version (stdcall_sig)
 {
   attribute mycall = stdcall;
 }

 attribute mycall void myfunc(int a)
 {
 }

 attribute mycall void myfunc2(int a)
 {
 }

 attribute mycall void myfunc3(int a)
 {
 }

 Rather than have to version each function separately, with its associated
 duplication of function bodies.
I see what it is you want, how about this: attribute (whatever) { all those functions } Then it's only one place to change the attribute.
Dec 02 2001
next sibling parent reply Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:
 
 "Sean L. Palmer" <spalmer iname.com> wrote in message
 news:9ue60n$13ps$1 digitaldaemon.com...
 On a semi-related note, can we define our own attributes?  For instance if
 I wanted to switch a whole lot of functions from one calling convention to
 another, I'd like to do this [...snip...]
I see what it is you want, how about this: attribute (whatever) { all those functions } Then it's only one place to change the attribute.
Unless you need to switch the calling convention for several modules at once. -RB
Dec 02 2001
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
Yeah, and that brings up a point.  Is this legal D?

version (verstdcall)
{
   attribute (stdcall) :
}
version (vercdecl)
{
   attribute (cdecl) :
}

void Foo(int) {}

I guess it is since version attributes don't introduce a new scope.  I doubt
that this form would work however:

version (verstdcall)
{
   attribute (stdcall) {
}
version (vercdecl)
{
   attribute (cdecl) {
}

void Foo(int) {}

}

Looks like parsing problems to me, no matter if you put the '{' inside the
version or outside it.

I guess my main point here is that people are going to want to version the
darndest things, so it should be supported at as many points in parsing as
possible without jeopardizing the rest of the language design.

Sean

"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3C0ABBFD.93A1A76B estarcion.com...
 Walter wrote:
 "Sean L. Palmer" <spalmer iname.com> wrote in message
 news:9ue60n$13ps$1 digitaldaemon.com...
 On a semi-related note, can we define our own attributes?  For
instance if
 I wanted to switch a whole lot of functions from one calling
convention to
 another, I'd like to do this [...snip...]
I see what it is you want, how about this: attribute (whatever) { all those functions } Then it's only one place to change the attribute.
Unless you need to switch the calling convention for several modules at once. -RB
Dec 03 2001
parent "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:9ufhcq$2ja5$1 digitaldaemon.com...
 Yeah, and that brings up a point.  Is this legal D?

 version (verstdcall)
 {
    attribute (stdcall) :
 }
 version (vercdecl)
 {
    attribute (cdecl) :
 }

 void Foo(int) {}
Yes. Thanks for that, I hadn't realized that worked!
 I guess it is since version attributes don't introduce a new scope.  I
doubt
 that this form would work however:

 version (verstdcall)
 {
    attribute (stdcall) {
 }
 version (vercdecl)
 {
    attribute (cdecl) {
 }

 void Foo(int) {}

 }
No, that won't work. It's important to remember that version(){} is part of the syntax, it is not a separate language interleaved into D.
 I guess my main point here is that people are going to want to version the
 darndest things, so it should be supported at as many points in parsing as
 possible without jeopardizing the rest of the language design.
While it's true one can write FORTRAN in any language <g>, to make D small and easy to comprehend, each feature needs a compelling reason for it.
Dec 03 2001
prev sibling parent reply "Sean L. Palmer" <spalmer iname.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:9ue9ed$17jq$1 digitaldaemon.com...
 "Sean L. Palmer" <spalmer iname.com> wrote in message
 news:9ue60n$13ps$1 digitaldaemon.com...
 Formal parameter list
I think this can be avoided by overloading with a version'd function.
I don't think that'd cover it completely. I'm thinking more of replacing a function signature entirely, not merely adding an overload. And not duplicating function body code.
 I see what it is you want, how about this:

     attribute (whatever)
     {
             all those functions
     }

 Then it's only one place to change the attribute.
Yes I suppose that'll do. Could even use "attribute :" ;) Just so long as no module-scope variables were in there anywhere. What'll happen if you apply an illegal attribute to something, such as a calling convention to a variable? Sean
Dec 03 2001
parent "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:9ufh3g$2j2s$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:9ue9ed$17jq$1 digitaldaemon.com...
 "Sean L. Palmer" <spalmer iname.com> wrote in message
 news:9ue60n$13ps$1 digitaldaemon.com...
 Formal parameter list
I think this can be avoided by overloading with a version'd function.
I don't think that'd cover it completely. I'm thinking more of replacing
a
 function signature entirely, not merely adding an overload.  And not
 duplicating function body code.
Use two inline wrapper functions and a third implementation function.
 What'll happen if you
 apply an illegal attribute to something, such as a calling convention to a
 variable?
Nothing. If it's a global variable, you'll get the appropriate name mangling.
Dec 03 2001