extern(C) vs. extern(Windows)

Mike Parker aldacron71 at yahoo.com
Mon Apr 2 03:23:08 PDT 2007


Frits van Bommel wrote:
> Frank Benoit (keinfarbton) wrote:
>> I have many functions. On linux they shall be extern(C), on win32 they
>> shall be extern(Windows). How do I do that?
> 
> Put this right above them:
> ---
> version(Windows) {
>     extern(Windows):
> } else {
>     extern(C):
> }
> ---
> (assuming extern(C) for anything but Windows)
> 
> If any other functions follow them, add "extern(D):" afterwards to 
> restore the default calling convention and mangling.

As I understand it, you have to do this without the brackets:

=====================
version(Windows)
     extern(Windows):
else
     extern(C):
=====================

This is how I do it in Derelict and it works fine. The reason I do this 
is because of the following section from the Attributes documentation:

=====================
attribute:		affects all declarations until the next }
     declaration;
     declaration;
     ...
=====================

So according to this, wrapping the externs within bracketed version 
statements should have no effect on declarations following the closing 
bracket. I haven't tried it with brackets, but if it works then either 
the implementation or the documentation is wrong.


More information about the Digitalmars-d-learn mailing list