C++: No Warning for passing value > 255 as parameter to a function requiring "unsigned char"

Martin Wodok m.wodok@osb-ag.de
Tue Jul 26 09:36:00 GMT 2005


Hi Gaby
hi Eljay,

thanks for your answer!

> Martin Wodok <m.wodok@osb-ag.de> writes:
> | Assigning 1000 is of course out of bounds for "unsigned char", thus the
>
> No, it is not.  Unsigned integer types are modulo types; it is no overflow.

Yes, they're modulo types, that's why this is NOT an error, but I still think 
that should be a WARNING. There're compilers like Tasking that throw a 
warning out on that one, so I'm really searching for a way to enable a 
warning for that one (maybe something like the warning -Wconversion), and not 
some extra code (Eljay, thanks anyway!!), because it should work on existing 
code and I don't want to get code-explosion (we're working embedded) just 
because some range-check that could be done by the compiler...

So it seems there's really no way for GCC to warn here?

Thanks again Gaby and Eljay,
/\/\artin

-- 
Dipl.-Inf. Martin Wodok
OSB AG Ingenieur- und IT-Dienstleistungen
Klenzestraße 38
80469 München
Telefon:  +49 (0)89/23 88 57-48
Telefax:  +49 (0)89/23 88 57-40



More information about the Gcc-help mailing list