ldc-developers/ldc — Issue #73: core.stdc.stdarg doesn't work on 64 bits
Author: SiegeLord
Created: 2012-02-03 03:00:45+00:00
State: open

```D
import stdarg = core.stdc.stdarg;
import vararg = core.vararg;
import std.stdio;

version(DigitalMars) version(X86_64)
import core.stdc.stdarg : __va_argsave_t;

// Use core.vararg
void test1(...)
{
foreach(type; _arguments)
{
writeln(vararg.va_arg!(int)(_argptr));
}
}

// Use core.stdc.stdarg #1
void test2(...)
{
foreach(type; _arguments)
{
writeln(stdarg.va_arg!(int)(cast(stdarg.va_list)_argptr));
}
}

// Use core.stdc.stdarg #2
void test3(...)
{
foreach(type; _arguments)
{
void[] buffer = new void[type.tsize];
stdarg.va_arg(cast(stdarg.va_list)_argptr, type, buffer.ptr);
writeln(*(cast(int*)buffer.ptr));
}
}

void main()
{
test1(42); //Works ok
test2(42); //Prints out junk
test3(42); //SIGSEGV
}
```

The ```va_arg``` functions in ```core.stdc.stdarg``` don't seem to work. They require a cast (see code) to even compile properly, and after that they don't work. All 3 functions compile and function fine on DMD 2.057 32 and 64 bits.