www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Versioned extern?

reply "Nick Sabalausky" <a a.a> writes:
Is there a way to have a section of code be extern(C) on one OS and 
extern(Windows) on another OS, without resorting making the code in question 
a mixin?

These doesn't appear to work:

------------------------------
version(Windows)
{
    enum callingConvention = "Windows";
}
else
{
    enum callingConvention = "C";
}

extern(mixin(callingConvention ))
{
    /+ ...code here... +/
}
------------------------------
version(Windows)
{
    extern(Windows):
}
else
{
    extern(C):
}

/+ ...code here... +/

extern(D):
------------------------------
Jul 23 2011
next sibling parent Brad Roberts <braddr puremagic.com> writes:
On Saturday, July 23, 2011 8:35:39 PM, Nick Sabalausky wrote:
 Is there a way to have a section of code be extern(C) on one OS and 
 extern(Windows) on another OS, without resorting making the code in question 
 a mixin?
 
 These doesn't appear to work:
 
 ------------------------------
 version(Windows)
 {
     enum callingConvention = "Windows";
 }
 else
 {
     enum callingConvention = "C";
 }
 
 extern(mixin(callingConvention ))
 {
     /+ ...code here... +/
 }
 ------------------------------
 version(Windows)
 {
     extern(Windows):
 }
 else
 {
     extern(C):
 }
 
 /+ ...code here... +/
 
 extern(D):
 ------------------------------
That specific pair of extern types with that specific set of versions --> extern(System)
Jul 23 2011
prev sibling next sibling parent =?UTF-8?B?QWxla3NhbmRhciBSdcW+acSNacSH?= <ruzicic.aleksandar gmail.com> writes:
If I'm not mistaken extern() accepts only Identifier, not expression.
I'm not really sure what's the best way to do that but I belive this
should work (haven't tested):

enum code =3D q{

   void func() {
           // do something
   }
};

version (Windows) {
   extern (Windows) {
       mixin(code);
   }
} else {
   extern (C) {
       mixin(code);
   }
}

On Sun, Jul 24, 2011 at 5:35 AM, Nick Sabalausky <a a.a> wrote:
 Is there a way to have a section of code be extern(C) on one OS and
 extern(Windows) on another OS, without resorting making the code in quest=
ion
 a mixin?

 These doesn't appear to work:

 ------------------------------
 version(Windows)
 {
 =C2=A0 =C2=A0enum callingConvention =3D "Windows";
 }
 else
 {
 =C2=A0 =C2=A0enum callingConvention =3D "C";
 }

 extern(mixin(callingConvention ))
 {
 =C2=A0 =C2=A0/+ ...code here... +/
 }
 ------------------------------
 version(Windows)
 {
 =C2=A0 =C2=A0extern(Windows):
 }
 else
 {
 =C2=A0 =C2=A0extern(C):
 }

 /+ ...code here... +/

 extern(D):
 ------------------------------
Jul 29 2011
prev sibling next sibling parent reply =?UTF-8?B?QWxla3NhbmRhciBSdcW+acSNacSH?= <ruzicic.aleksandar gmail.com> writes:
Ouh, haven't read that you don't want code to be mixed-in.. In that
case.. I dunno :)

2011/7/29 Aleksandar Ru=C5=BEi=C4=8Di=C4=87 <ruzicic.aleksandar gmail.com>:
 If I'm not mistaken extern() accepts only Identifier, not expression.
 I'm not really sure what's the best way to do that but I belive this
 should work (haven't tested):

 enum code =3D q{

 =C2=A0 void func() {
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // do something
 =C2=A0 }
 };

 version (Windows) {
 =C2=A0 extern (Windows) {
 =C2=A0 =C2=A0 =C2=A0 mixin(code);
 =C2=A0 }
 } else {
 =C2=A0 extern (C) {
 =C2=A0 =C2=A0 =C2=A0 mixin(code);
 =C2=A0 }
 }

 On Sun, Jul 24, 2011 at 5:35 AM, Nick Sabalausky <a a.a> wrote:
 Is there a way to have a section of code be extern(C) on one OS and
 extern(Windows) on another OS, without resorting making the code in ques=
tion
 a mixin?

 These doesn't appear to work:

 ------------------------------
 version(Windows)
 {
 =C2=A0 =C2=A0enum callingConvention =3D "Windows";
 }
 else
 {
 =C2=A0 =C2=A0enum callingConvention =3D "C";
 }

 extern(mixin(callingConvention ))
 {
 =C2=A0 =C2=A0/+ ...code here... +/
 }
 ------------------------------
 version(Windows)
 {
 =C2=A0 =C2=A0extern(Windows):
 }
 else
 {
 =C2=A0 =C2=A0extern(C):
 }

 /+ ...code here... +/

 extern(D):
 ------------------------------
Jul 29 2011
parent "Nick Sabalausky" <a a.a> writes:
"Aleksandar Ruzicic" <ruzicic.aleksandar gmail.com> wrote in message 
news:mailman.1954.1311949602.14074.digitalmars-d-learn puremagic.com...
Ouh, haven't read that you don't want code to be mixed-in.. In that
case.. I dunno :) It's not that I didn't want to, it's just that I was wondering if there was a better way. Fortunately, version(System) is exactly what I needed in my specific case, even if it isn't a general solution.
Jul 30 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Sat, 23 Jul 2011 23:35:39 -0400, Nick Sabalausky <a a.a> wrote:

 Is there a way to have a section of code be extern(C) on one OS and
 extern(Windows) on another OS, without resorting making the code in  
 question
 a mixin?

 These doesn't appear to work:

 ------------------------------
 version(Windows)
 {
     enum callingConvention = "Windows";
 }
 else
 {
     enum callingConvention = "C";
 }

 extern(mixin(callingConvention ))
 {
     /+ ...code here... +/
 }
 ------------------------------
 version(Windows)
 {
     extern(Windows):
 }
 else
 {
     extern(C):
 }

 /+ ...code here... +/

 extern(D):
 ------------------------------
does this work? private void fnImpl(...) { // code here } version(Windows) { extern(Windows) fn(...) {fnImpl();} } else { extern(C) fn(...) {fnImpl();} } -Steve
Jul 29 2011
prev sibling parent Trass3r <un known.com> writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5739#c3
Jul 29 2011