www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23494] New: C-style variadic functions not working correctly


          Issue ID: 23494
           Summary: C-style variadic functions not working correctly
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ogion.art gmail.com

extern (C) void variadic(int* p, int x, int y, int z, const char *fmt, ...) {
    import core.stdc.stdarg;
    import core.stdc.stdio;

    va_list args;
    va_start(args, fmt);
    foreach (_; 0..2) {
        char* c;
        va_arg(args, c);
        printf("%s\n", c);

void main() {
    variadic(null, 0, 0, 0, "%s %s", "one".ptr, "two".ptr);

This should print:

On Windows, this works correctly in a 32-bit build. When compiled with -m64
flag, this prints:
%s %s

Tinkering with parameters preceding `fmt` affects the output.

Nov 18 2022