Re: fun with ?:

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

 




On Wed, 23 May 2007, Derek M Jones wrote:
> > 
> > passes with -pedantic -std=c99.  Replacing that with 1 + n - n + n - n
> > is still OK with gcc; 1 + n + n - n - n is not.
> > 
> > So that's hardly an example of, well, anything.
> 
> It is an example of order of evaluation mattering when overflow
> occurs.

No it isn't.

"1 + n - n" can overflow equally as "1 + n + n - n -n" can, and if you 
want them to do saturation or something, you cannot optimize _either_ of 
them to just "1". If "n" is MAX_INT, then with saturating arithmetic, 
neither of them results in 1.

Not that signed overflow is even specified by the C standard (and 
unsigned is specified to be well-behaved).

So it seems to be purely a compiler misfeature. No excuses.

			Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux