[Issue 9028] `main` is trated sometimes as having C calling convention and sometimes as having D convention

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 15 02:01:38 PST 2012


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


Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|`main` is trated sometimes  |`main` is trated sometimes
                   |as having C linkage and     |as having C calling
                   |sometimes as having D       |convention and sometimes as
                   |linkage                     |having D convention


--- Comment #2 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2012-11-15 13:01:22 MSK ---
(In reply to comment #1)

Sorry, it's calling convention, not linkage.

I mean C calling convention is used in first two cases but as `typeof(main)`
tells it is `extern(D)` D calling convention is used in the last case.

So `Access Violation` isn't mandatory but possible.

I.e. this will print decreasing ESP:
---
import std.stdio;

void main(string[] args)
{
    if(!args.length) return;

    size_t esp;
    foreach(i; 0 .. 2 ^^ 20)
    {
        auto p = &main; // D linkage used
        p(null); // stack corruption, results in Access Violation
      //asm { add ESP, 0x8; } // uncomment to fix
        asm { mov esp, ESP; }
        writefln("%X", esp);
    }
}
---

-- 
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