Hi all,
I too have tried to use the va_arg macros in <unix_stdarg.h> from the Palm
3.5 Support directory (with CW7, btw).
With apologies for the length of this, here is what I've run into. Please
let me know if / where I've gotten confused.
I've hit three problems so far involving mismatches between the size of an
object put into the variable argument space and the size read out.
1) Setting the 4byte int flag caused an unsigned short to be put in as 4
bytes instead of 2. Metrowerks suggested using
#pragma no_register_coloring on
to fix this. Since I had already switched to 2byte Ints, I haven't tried
that.
2)NULL in C++ is an Int, so when I switched to 2bytes, it didn't work as a
placeholder for a pointer. That is, you call the variable arg func with
NULL, and try to call va_arg(argp, void*) and you get a problem.
Changing the definition of NULL gave me the creeps since I didn't like
having to correct the system headers, but this worked:
#ifndef NULL
#ifdef __cplusplus
#define NULL 0L
#else
#define NULL ((void*) 0)
#endif
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 *);
What's the problem?
Well, on the MC68000 family, if you access a word or a long-word operand or
instruction at an odd address, you get an address error.
So, when I called the variable arg function the compiler (in the guise of
the ... operator) put a byte of padding into the variable argument space to
keep the addressing even.
The va_arg macro I find in the Palm 3.5 Support unix_stdarg.h makes no
adjustment for byte-alignment when reading the variables.
The symptom is
1) x gets 0 (the padding byte value) instead of whatever byte I passed in
2) attempting the y assignment causes an address error because argp is
pointing at the byte I intended for x and the first 3 bytes I intended for
y.
So here is my question:
In what manner does Palm (whom Metrowerks tells me provided the relevent
header(s)) support/recommend using the contents of unix_stdarg.h?
I've posted this here, since I see others struggling with this (or about
to...)
Jim Schram posted the most informative piece I saw here:
RE: Multiple parameter functions
http://www.escribe.com/computing/pcpqa/m41265.html
-- Chuck
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/