[Issue 9028] New: `main` is trated sometimes as having C linkage and sometimes as having D linkage

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 15 00:59:35 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9028

           Summary: `main` is trated sometimes as having C linkage and
                    sometimes as having D linkage
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2012-11-15 11:59:34 MSK ---
---
void main(string[] args)
{
    if(!args.length) return;

    foreach(i; 0 .. 1)
        main(null); // ok, C linkage used

    foreach(i; 0 .. 1)
        (&main)(null); // also ok

    foreach(i; 0 .. 1)
    {
        auto p = &main; // D linkage used
        p(null); // stack corruption, results in Access Violation
      //asm { add ESP, 0x8; } // uncomment to fix
    }
}
---

Note: do not mark `main` as `extern(C)` because it will lead to not calling
runtime initialization stuff.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list