[Issue 22960] importC: K&R-style functions assume variadic calling convention

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 14 06:46:10 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=22960

--- Comment #5 from Walter Bright <bugzilla at digitalmars.com> ---
Consider:
--------------
int abc();
int def(const char *, ...);
int ghi(const char *, int i);

int main()
{
    abc("hello world %d\n", 1);
    def("hello world %d\n", 2);
    ghi("hello world %d\n", 3);
    return 0;
}
-------------
Compiled with gcc:
-------------
main:
                push    RBP
                mov     RBP,RSP
                mov     ESI,1
                mov     EDI,offset FLAT:.rodata at 32
                mov     EAX,0
                call      abc at PC32
                mov     ESI,2
                mov     EDI,offset FLAT:.rodata at 32
                mov     EAX,0
                call      def at PC32
                mov     ESI,3
                // look ma, no mov EAX,0 !!
                mov     EDI,offset FLAT:.rodata at 32
                call      ghi at PC32
                mov     EAX,0
                pop     RBP
                ret
--------
The code generated for calls to abc() and def() is the same, it is ghi() that
is different.

--


More information about the Digitalmars-d-bugs mailing list