C++: No Warning for passing value > 255 as parameter to a function requiring "unsigned char"
Eljay Love-Jensen
eljay@adobe.com
Fri Jul 22 15:22:00 GMT 2005
Hi Martin,
Change this...
unsigned char var = 1000;
...to this...
unsigned char var = MakeUnsignedChar(1000);
And add the function:
#include <stdio.h>
#include <stdlib.h>
unsigned char MakeUnsignedCharFromInt(int x)
{
if(x > 255 || x < 0)
{
fprintf(stderr, "Parameter %d out of unsigned char bounds.", x);
abort();
}
return (unsigned char)x;
}
HTH,
--Eljay
More information about the Gcc-help
mailing list