The code below should explain the problem sufficiently:
-------------------------------------------------------
module vararg;
// Works
void a(...)
{
void* v = _argptr;
}
// Works
void b(char* fmt, ...)
{
void* v = _argptr;
}
// Error: variadic functions with non-D linkage must have at least one parameter
// which is correct
extern(C)
void c(...)
{
void* v = _argptr;
}
// Error: undefined identifier _argptr
// vararg.d(22): Error: cannot implicitly convert expression (_argptr) of type int to void*
// this is contrary to spec!
extern(C)
void d(char* fmt, ...)
{
void* v = _argptr;
}
void main()
{
a("a", 2, 3.0);
b("b", 2, 3.0);
c("c", 3, 3.0);
d("c", 3, 3.0);
}
Comment #1 by lio+bugzilla — 2007-02-09T02:01:25Z
I don't think this is a bug. For extern(C) you need std.c.stdarg, va_start..va_end..
Comment #2 by tomas — 2007-02-09T11:31:20Z
According to the spec the _argptr variable should be available...
So it most definitely is!
Comment #3 by venix1 — 2010-08-26T17:26:47Z
While working on GDC, it was found this bug still exists in 1.063.
The problem appears to be an if statement in func.c around line 811.
"parameters" is not initialized until further down in the function. By substituting "f->parameters" the problem is resolved.
-----------------------------------------------------------
// Original if statement
if (f->linkage == LINKd || (parameters && parameters->dim))
// Modified if statement
if (f->linkage == LINKd || (f->parameters && Parameter::dim(f->parameters)))
GDC ticket.
http://bitbucket.org/goshawk/gdc/issue/57/c-style-variadic-functions-broken