Re: fun with ?:

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

 




On Thu, 24 May 2007, Derek M Jones wrote:
> 
> Saturated arithmetic kills off so many optimizations because reordering
> an expression might produce different results.

Yes. However, the FP people do have solutions to that, for all the same 
reasons.

(ie, you can add rules like:
 - parentheses have meaning outside of just precedence, and disable 
   associativity-based ordering optimizations.
 - the normal C side effect boundaries also act as ordering boundaries for 
   arithmetic.

> This is the point of the discussion that has got me confused.
> What compiler misfeature?  Perhaps I am using the 'wrong' version
> of gcc (version 4.0.2), but I get the expected wrapping behavior (ie,
> the compiler tries to behave at translate time the same way as st
> runtime).

The problem that Al was pointing to that sometimes gcc will do *constant 
folding* at parse time, and treat "1+n-n" as a compile-time constant in 
situations where that simply isn't valid C.

Try this:

	[torvalds@woody ~]$ cat t.c
	extern int n;
	int a[1 + n - n];
	[torvalds@woody ~]$ gcc -c -Wall t.c

and notice the lack of any error what-so-ever. With sparse, you get

	[torvalds@woody ~]$ sparse -Wall t.c
	t.c:2:13: error: bad constant expression

now, change the "1+n-n" into "1+n+n-n-n", and notice what gcc says:

	[torvalds@woody ~]$ gcc -c -Wall t.c
	t.c:2: error: variably modified ‘a’ at file scope

iow, gcc actually thinks that "1+n-n" is somehow different from 
"1+n+n-n-n".

Which was Al's point.

		Linus

[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