Re: Optimisations and undefined behaviour

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

 



On 11/06/2015 01:32 PM, David Brown wrote:
> How about this case:
> 
> int foo(int x) {
> 	if (x > 1290) {
> 		printf("X is wrong here %d, but we don't care\n", x);
> 	}
> 	return x*x*x;
> }
> 
> The compiler can eliminate the check and the printf.

I don't think the compiler can do that because printf has an externally
visible effect, which is sequenced before the undefined behavior, so
this program transformation would not be permitted under the as-if rule.

Florian




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux