$ cat test.d
extern (C): int i;
import std.stdio;
void main(){
write(i);
}
$ dmd -run test
--- killed by signal 11
$ rdmd test
Segmentation fault (core dumped)
Comment #1 by mxfomin — 2015-05-12T11:57:32Z
That's funny bug. Extern(C): makes 'fall through' effect on main declaration which hijacks druntime main definition, which prevents running module ctors, so some internal data is not initialized properly. This works as expected:
import std.stdio;
void main(){
writeln(i);
}
extern (C): int i;
According to spec http://dlang.org/attribute.html
attribute declaration; // affects the declaration
attribute: // affects all declarations until the end of
// the current scope
declaration;
declaration;
...
attribute { // affects all declarations in the block
declaration;
declaration;
...
}
It seems that it implies file scope, so it works as intended, although it is confusing. Tentatively closed as resolved-invalid.