Thread overview
Help with stdarg templates
Jun 02, 2004
Ted Williams
Jun 02, 2004
J C Calvarese
Jun 02, 2004
Ted Williams
Jun 05, 2004
J Anderson
June 02, 2004
Hi

I am using the stdarg templates as in the following code:

=====
int WriteLine( char[] format, ... )
{
    va_list args;

    alias va_start!(char []) start;
    alias va_arg!(Object) arg;

    start( args, format );
.
.
.
=====

When I compile this I get the following errors (with line numbers adjusted:)

console.d(8): function va_start (va_list ap,char[]parmn) does not match
argume nt types (ubyte*,char[])
console.d(8): cannot implicitly convert ubyte* to va_list

I've tried everything I can think of and can't find any combination of things that will compile.  I think I have a fundamental flaw in my understanding of the way templates work.  Can anyone help shed some light on this for me?

Thanks,
Ted


June 02, 2004
Ted Williams wrote:
> Hi
> 
> I am using the stdarg templates as in the following code:
> 
> =====
> int WriteLine( char[] format, ... )
> {
>     va_list args;
> 
>     alias va_start!(char []) start;
>     alias va_arg!(Object) arg;
> 
>     start( args, format );

This at least compiles:

import std.c.stdarg;
int WriteLine( char[] format, ... )
{
    va_list args;
    va_start!(char []) (args, format);
    va_end(args);
    return 1;
}
void main() {}

Here's a fuller example is available from http://www.dsource.org/tutorials/index.php?show_example=94
----------------------------------------------------------

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);

    int i;
    i = va_arg!(typeof(i))(ap);
    printf("i = %d\n", i);

    long l;
    l = va_arg!(typeof(l))(ap);
    printf("l = %lld\n", l);

    uint k;
    k = va_arg!(typeof(k))(ap);
    printf("k = %u\n", k);

    va_end(ap);

    return i + l + k;
}

void main()
{
    int j;

    j = foo("hello", 3, 23L, 4);
    printf("j = %d\n", j);
    assert(j == 30);
}


Hope that helps.

> ..
> ..
> ..
> =====
> 
> When I compile this I get the following errors (with line numbers adjusted:)
> 
> console.d(8): function va_start (va_list ap,char[]parmn) does not match
> argume nt types (ubyte*,char[])
> console.d(8): cannot implicitly convert ubyte* to va_list
> 
> I've tried everything I can think of and can't find any combination of
> things that will compile.  I think I have a fundamental flaw in my
> understanding of the way templates work.  Can anyone help shed some light on
> this for me?
> 
> Thanks,
> Ted

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
June 02, 2004
"J C Calvarese" <jcc7@cox.net> wrote in message news:c9jn35$gu9$1@digitaldaemon.com...
> Ted Williams wrote:
> > Hi
> >
> > I am using the stdarg templates as in the following code:
> >
> > =====
> > int WriteLine( char[] format, ... )
> > {
> >     va_list args;
> >
> >     alias va_start!(char []) start;
> >     alias va_arg!(Object) arg;
> >
> >     start( args, format );
>
> This at least compiles:
>
> import std.c.stdarg;
> int WriteLine( char[] format, ... )
> {
>      va_list args;
>      va_start!(char []) (args, format);
>      va_end(args);
>      return 1;
> }
> void main() {}
>
> Here's a fuller example is available from http://www.dsource.org/tutorials/index.php?show_example=94
> ----------------------------------------------------------
>
> 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);
>
>      int i;
>      i = va_arg!(typeof(i))(ap);
>      printf("i = %d\n", i);
>
>      long l;
>      l = va_arg!(typeof(l))(ap);
>      printf("l = %lld\n", l);
>
>      uint k;
>      k = va_arg!(typeof(k))(ap);
>      printf("k = %u\n", k);
>
>      va_end(ap);
>
>      return i + l + k;
> }

<snip>

I made my code look like the code above, and it still gives the same compiler error as before:

console.d(101): function va_start (va_list ap,char[]parmn) does not match
argument types (ubyte*,char[])
console.d(101): cannot implicitly convert ubyte* to va_list

Could it be a compiler bug?


June 05, 2004
Ted Williams wrote:

>Hi
>
>I am using the stdarg templates as in the following code:
>
>=====
>int WriteLine( char[] format, ... )
>{
>    va_list args;
>
>    alias va_start!(char []) start;
>    alias va_arg!(Object) arg;
>
>    start( args, format );
>.
>.
>.
>=====
>
>When I compile this I get the following errors (with line numbers adjusted:)
>
>console.d(8): function va_start (va_list ap,char[]parmn) does not match
>argume nt types (ubyte*,char[])
>console.d(8): cannot implicitly convert ubyte* to va_list
>
>I've tried everything I can think of and can't find any combination of
>things that will compile.  I think I have a fundamental flaw in my
>understanding of the way templates work.  Can anyone help shed some light on
>this for me?
>
>Thanks,
>Ted
>
>  
>


import std.c.stdarg;

int WriteLine( char[] format, ... )
{
   va_list args;

   alias va_start!(char []) start;
   alias va_arg!(Object) arg;

   start( args, format );

   return 0;
}

void main(char[][] args)
{
   WriteLine("test");
}

Works for me in dmd (.91), so I can't see anything wrong with your code.

-- 
-Anderson: http://badmama.com.au/~anderson/