va_arg issues with different gcc versions
Wed Jan 8 19:52:00 GMT 2003
> From email@example.com Wed Jan 8 06:41:23 2003
> On redhat 7.0, this code will compile with gcc 2.95.2 but not with 2.96:
> va_list ap;
> unsigned char b = va_arg(ap, unsigned char);
> Is there a way to fix this code to make it friendly to all versions of gcc?
Sorry, don't have time to look this up to make sure I'm pointing
you in the right direction, but hope this is a help...
I think Standard C requires the second argument va_arg()
to be a "widened" type per the usual assignment conversions.
I also think that whereas traditional C was "unsigned preserving"
in the assignment conversions -- and don't recall the details with
chars, but there were a few subtleties -- Standard C is "value
So, since by this reasoning, unsigned char would be "promoted"
to an int, and I would suggest:
unsigned char b = va_arg(ap, int);
where b would be cast to unsigned char on initialization.
More information about the Gcc-help