> 3) byte-alignment padding trips up va_arg macro.
> Ok, here's where I'm hoping to get a guru's attention.
> As far as I can tell, the va_arg macro has no way of handling this
sequence:
>
>
> x = va_arg(argp, unsigned char);
> y = va_arg(argp, void *);
The problem is that va_arg(argp, unsigned char) is never meaningful.
Arguments pushed onto the stack for variable argument list functions are
always at least sizeof(int) bytes. If you have a parameter you want to
treat as unsigned char, you can read it off as unsigned int, then
downcast. The compiler won't push just one byte -- it will have
converted any expressions to at least int before pushing.
The NULL problem is also similar -- in C++, 0 is the NULL pointer,
however C++ needs some pointer context to do this interpretation. A
variable argument list doesn't provide this context. You can fix this
by saying "(void *) NULL" or whatever type your passing. This will use
the 4-byte form when pushing.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/