version and extern problems
Jason House
jason.james.house at gmail.com
Sun Jul 8 06:55:26 PDT 2007
Walter Bright wrote:
> Bug 1311 http://d.puremagic.com/issues/show_bug.cgi?id=1311
> is about using version declarations to control part of a following
> declaration (or series of declarations):
>
> -------------------------
> version(Windows)
> extern(Windows):
> else
> extern(C):
>
> typedef void function() foo;
> --------------------------
>
> This does not work now, and it was a bug that it ever did appear to
> work. The issue is that version declarations can only affect entire
> declarations, not parts of them. An extern statement with a : is
> implicitly the same as:
>
> ----------------
> extern(Windows):
> int a;
> int b;
> -----is same as---
> extern(Windows)
> {
> int a;
> int b;
> }
> -----------------
This seems like a real loss for the convenience of D. One of the assets
of the D language is that it makes a lot of things simple. The example
in the bug is fairly intuitive and easy to write.
> That cannot be split up with a version declaration; it would be like
> trying to make:
>
> version (Windows)
> int
> else
> long
> x;
>
> work. The old behavior of dmd contained a serious (unreported) bug where
> such constructs would cause forward references to behave unpredictably.
This restriction seems reasonable. It'd be really, really tough to
handle. In my mind, the issue is that the : operator might make sense
if the attribute: only applied to it's contained scope. In this case,
however, that doesn't really make sense, because version statements
don't really have their own scope... Otherwise, variable definitions
inside of them wouldn't be available externally.
More information about the Digitalmars-d
mailing list