Re: unary minus operator applied to unsigned type, result still unsigned



> could you give the output of
> [ sample program ]

Yes, this prints the same output when compiled with MS C. Actually
that sample program doesn't even trigger the warning. Apparently the
warning is given only if unary minus is applied to an unsigned int,
which is being assigned to an int (or passed as an int).

As the end result seems to be the same as with gcc, I guess I can
safely ignore these warnings. Still, IMHO, it would make the intended
effect clearer to the human reader of the program if an (int) cast
were used when an unsigned value is being negated.

(Note that if you use unsigned int instead of unsigned short in the
sample program, you get the output - 5 = 4294967291.000000, also with gcc)

--tml



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]