Optimisations and undefined behaviour
Florian Weimer
fweimer@redhat.com
Mon Nov 9 15:04:00 GMT 2015
On 11/09/2015 04:00 PM, Andrew Haley wrote:
> 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.
If the printf has no effect, you can obviously leave it out.
I think the goal here was to convince me that even if the printf has a
visible effect (in the sense that I could read its output), it is still
conforming to remove it. This is the part I have problems with.
Florian
More information about the Gcc-help
mailing list