[Issue 14426] Segfault for missing extern variable
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Tue May 12 04:57:32 PDT 2015
    
    
  
https://issues.dlang.org/show_bug.cgi?id=14426
Maxim Fomin <maxim-fomin at outlook.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim-fomin at outlook.com
         Resolution|---                         |INVALID
--- Comment #1 from Maxim Fomin <maxim-fomin at outlook.com> ---
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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list