Optimisations and undefined behaviour
Andrew Haley
aph@redhat.com
Mon Nov 9 15:00:00 GMT 2015
On 11/09/2015 02:56 PM, Richard Earnshaw wrote:
> On 09/11/15 14:29, Andrew Haley wrote:
>> Here it is again:
>>
>> int foo(int x) {
>> if (x > 1290) {
>> printf("X is wrong here %d, but we don't care\n", x);
>> }
>> return x*x*x;
>>
>> Here, the printf writes to a stream then the UB happens.
>
> Not if setvbuf has been used to make the stream unbuffered.
It hasn't. And I know it hasn't because it's my example.
And besides, the UB might cause the computer to crash before the data
has been written to stdout by the kernel; the same reasoning applies.
Andrew.
More information about the Gcc-help
mailing list