July 08, 2004
"Hauke Duden" <H.NS.Duden@gmx.net> wrote in message news:c795fn$1kp2$1@digitaldaemon.com...
> Walter wrote:
>   > I think the easiest way to make this work is just cut and paste the
> > declarations:
> I think copying code is the worst thing you could do. This kind of stuff can quickly become a maintenance nightmare. The whole point of conditional compilation is to have the same piece of code work in different environments, so that you will NOT have to manually copy all changes to all targets (and inevitably forget some).

Significantly mitigating that is the block can be copied en masse, the extern statement does not have to be added line by line as it would in C++.

> Otherwise you could just as well create different source files for each version and only compile the one you want.

What I don't really understand is why even use the Windows calling convention for newly written C code. It offers nothing beyond uglification of the C source.

> Just an idea, but does/could alias work for such situations? Like:
>
> version(Windows)
> alias extern(Windows) extern(MyConvention);
> else
> alias extern(C) extern(MyConvention);
>
> extern(MyConvention):
> ...

That syntactically can work, but it's something I'd rather avoid.

> However, my guess is that version will need to become more powerful anyway. There is a lot of conditional compilation stuff that just isn't possible in D right now. Especially boolean expressions among version parameters (i.e. version( a || b && !c) are a must have, IMHO.

I'm familiar with a lot of uses of expressions for conditional compilation, including using it myself, and over the years I began to suspect it was way overused. Instead, an identifier should be created for each 'feature' one wants to use.

Then, && is:
    version (Foo) version (Bar) version=Feature;
|| is:
    version (Foo) version=Feature;
    version (Bar) version=Feature;
and ! is:
    version (Foo) { } else version=Feature;



July 09, 2004
On 04 May 2004, Andy Friesen <andy@ikagames.com> wrote:

> This should get you where you want to be:
> 
> version (Win32) {
>      extern (Windows):
> } else {
>      extern (C):
> }
> 
> void glThingie(...); // this will be extern (Windows) on win32,else
>                       // extern(C)
> void glOtherThingie(...);
> // et cetera

Great!  I had the same problem and your solution works.  But I'm new to D, and I'm not clear about the syntax with a colon.  Does the effect just continue to then end of the source file?  Can you give a reference to where this is explained?

Dave

-- 
D.a.v.i.d  T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
July 09, 2004
David Tiktin wrote:

> On 04 May 2004, Andy Friesen <andy@ikagames.com> wrote:
> 
>> This should get you where you want to be:
>> 
>> version (Win32) {
>>      extern (Windows):
>> } else {
>>      extern (C):
>> }
>> 
>> void glThingie(...); // this will be extern (Windows) on win32,else
>>                       // extern(C)
>> void glOtherThingie(...);
>> // et cetera
> 
> Great!  I had the same problem and your solution works.  But I'm new to D, and I'm not clear about the syntax with a colon.  Does the effect just continue to then end of the source file?  Can you give a reference to where this is explained?
> 
> Dave
> 

see http://www.digitalmars.com/d/attribute.html where it says
 attribute:           affects all declarations until the next }
    declaration;
    declaration;
    ...

(or I guess until the end of the file)

Next ›   Last »
1 2
Top | Discussion index | About this forum | D home