Thread overview | |||||
---|---|---|---|---|---|
|
November 24, 2004 va_start | ||||
---|---|---|---|---|
| ||||
Hello, this programm compile successfully with dmd but with gdc i get the following error message: v_args1.d:6: template instance va_start!(char[]) va_start is not a template declaration, it is a function v_args1.d:6: function expected before (), not 'void' import std.c.stdarg; int foo(char[] x, ...) { va_list ap; va_start!(typeof(x))(ap, x); printf("&x = %p, ap = %p\n", &x, ap); printf("%.*s\n",x); int i; i = va_arg!(typeof(i))(ap); printf("i = %d\n", i); va_end(ap); return i; } int main() { int j; j = foo("hello", 3); printf("j = %d\n", j); return 0; } |
November 24, 2004 Re: va_start | ||||
---|---|---|---|---|
| ||||
Posted in reply to nix | nix wrote:
> Hello, this programm compile successfully with dmd but with gdc i get the following error message:
>
> v_args1.d:6: template instance va_start!(char[]) va_start is not a template declaration, it is a function v_args1.d:6: function expected before (), not 'void'
>
>
>
> import std.c.stdarg;
>
> int foo(char[] x, ...) {
>
> va_list ap; va_start!(typeof(x))(ap, x); printf("&x = %p, ap = %p\n", &x, ap); printf("%.*s\n",x);
>
> int i; i = va_arg!(typeof(i))(ap); printf("i = %d\n", i); va_end(ap);
>
> return i; }
>
> int main() { int j;
>
> j = foo("hello", 3); printf("j = %d\n", j);
>
> return 0; }
>
>
>
Argh, I didn't implement va_start correctly. As a workaround, you can use "va_start(ap,x);"
Is foo supposed to be an "extern(C)" function? If not, you can use the predefined variable "_argptr" and there is no need to call va_start.
David
|
November 24, 2004 Re: va_start | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Friedman | Thank you for the quick answer
Manfred
David Friedman wrote:
> nix wrote:
>> Hello,
>> this programm compile successfully with dmd but with
>> gdc i get the following error message:
>>
>> v_args1.d:6: template instance va_start!(char[]) va_start is not a
>> template declaration, it is a function
>> v_args1.d:6: function expected before (), not 'void'
>>
>>
>>
>> import std.c.stdarg;
>>
>> int foo(char[] x, ...) {
>>
>> va_list ap;
>> va_start!(typeof(x))(ap, x);
>> printf("&x = %p, ap = %p\n", &x, ap);
>> printf("%.*s\n",x);
>>
>> int i;
>> i = va_arg!(typeof(i))(ap);
>> printf("i = %d\n", i);
>> va_end(ap);
>>
>> return i;
>> }
>>
>> int main() {
>> int j;
>>
>> j = foo("hello", 3);
>> printf("j = %d\n", j);
>>
>> return 0;
>> }
>>
>>
>>
>
> Argh, I didn't implement va_start correctly. As a workaround, you can
> use "va_start(ap,x);"
>
> Is foo supposed to be an "extern(C)" function? If not, you can use the predefined variable "_argptr" and there is no need to call va_start.
>
> David
|
Copyright © 1999-2021 by the D Language Foundation