signed is undefined and has been since 1992 (in GCC)

Paul Koning pkoning@equallogic.com
Tue Jun 28 20:18:00 GMT 2005


>>>>> "Robert" == Robert Dewar <dewar@adacore.com> writes:

 Robert> I am puzzled, why would *ANYONE* who knows C use int rather
 Robert> than unsigned if they want wrap around semantics?

Because most people don't follow the rule that "always use unsigned
variables unless you know that it really needs to be signed".

And also because most people believe that C applies normal computer
arithmetic, and they believe that normal computer arithmetic is
wrapped 2's complement.  (And indeed it usually is, give or take some
bizarre exceptions like MAX_INT % -1)

We all know better, but how tiny is the fraction of C programmers who
have ever even *seen* the ANSI C spec, much less know in detail what
it says?

	paul



More information about the Gcc mailing list