This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: va_arg issues with different gcc versions


> From gcc-help-return-11193-pkurpis=keck.hawaii.edu@gcc.gnu.org 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 
preserving."

So, since by this reasoning, unsigned char would be "promoted"
to an int, and I would suggest:

	va_list ap;
	unsigned char b = va_arg(ap, int);

where b would be cast to unsigned char on initialization.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]