extern(C) vs. extern(Windows)

Max Samukha samukha at voliacable.com
Mon Apr 2 03:51:54 PDT 2007


On Mon, 02 Apr 2007 19:23:08 +0900, Mike Parker <aldacron71 at yahoo.com>
wrote:

>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):
>=====================

You can use brackets because version does not create a scope.
>
>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