main.d: ======= import versionextern; void main() { foo(); } versionextern.d: ================ version = Bla; version(Bla) { extern(Windows): } else version(Blub) { extern(C): } void foo(); yields: Symbol Undefined _D13versionextern3fooFZv no matter what version is defined. removing the parentheses and else: version(Bla) extern(Windows): version(Blub) extern(C): even results in: main(5): Error: undefined identifier foo I'm not sure if this is a rejects-valid or accepts-invalid issue.
In this particular case you could use "extern (System)". But this should probably be fixed anyway.
Yep I know, but the original code is like: version(CL_VERSION_1_1) extern(System): else extern(C):
This is not a bug. A linkage declaration that ends in ':' runs to the end of the block, which in this case is the end of the version declaration.
But how does he get "Error: undefined identifier foo"? Shouldn't "foo" just be declared as a regular function?
Yep, the second issue still persists. I found out what I originally wanted to do can be achieved via: extern(C): version(Bla) extern(Windows): // though replacing this with mixin("extern(Windows):"); doesn't work, then extern(C) wins void foo(); But as soon as you have 2 blocks like version(Bla) extern(Windows): version(Blub) extern(C++): and Blub isn't set, it fails with "undefined identifier foo"
Ah never mind, turns out it doesn't work. extern(C): version(Bla) extern(Windows): void foo(); fails as soon as Bla isn't defined. I guess it has to do with the parser. Because of the ':' it probably gets read like: version(Bla) { extern(Windows): void foo(); }
(In reply to comment #4) > But how does he get "Error: undefined identifier foo"? Shouldn't "foo" just be > declared as a regular function? It gets parsed like: extern(C): void foo(); and so foo is undefined.