extern(C) vs. extern(Windows)
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Mon Apr 2 03:44:43 PDT 2007
Mike Parker wrote:
> Frits van Bommel wrote:
[snip]
>> ---
>> version(Windows) {
>> extern(Windows):
>> } else {
>> extern(C):
>> }
>> ---
[snip]
>
> As I understand it, you have to do this without the brackets:
>
> =====================
> version(Windows)
> extern(Windows):
> else
> extern(C):
> =====================
The braces are redundant if there's only one thing in them, yes. But
adding them doesn't change the effect (in other words: you don't _have_
to do it without them, but you _can_) and I typically just put them in
even where they aren't strictly needed. (IMO that makes it clearer what
exactly is compiled)
> 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.
The braces don't have anything to do with attributes, so you're looking
in the wrong place. You should have been looking at
http://www.digitalmars.com/d/version.html, especially the line "No new
scope is introduced, even if the DeclarationBlock or Statement is
enclosed by { }."
That line should probably be something like "affects all declarations
until the end of the current scope". I've created a bug report:
http://d.puremagic.com/issues/show_bug.cgi?id=1090
More information about the Digitalmars-d-learn
mailing list