gcc warnings
John Love-Jensen
eljay@adobe.com
Wed Oct 17 11:48:00 GMT 2007
Hi Jiri,
It's valid C code to assign from a variable of greater type to one of
smaller type.
I think that this is very unfortunate. I presume you do as well. Alas.
You can act upon it programmatically, in runtime, if you do something like:
#include "stdio.h"
unsigned char LongAsUnsignedChar(long c)
{
if(c > 255 || c < 0)
{
fprintf(stderr, "Error: %ld outside of 0,255 range\n", c);
}
return c;
}
int main()
{
long a = 10000;
unsigned char b = LongAsUnsignedChar(a);
printf("%d\n", b);
return b;
}
Alternatively, you can use a B&D language like Ada where such assignments
cannot happen silently and need explicit conversion.
HTH,
--Eljay
More information about the Gcc-help
mailing list