Hi ! help please

Vincent Diepeveen diep@xs4all.nl
Sat Jan 2 13:26:00 GMT 2016


Assuming function f() has been defined
Comparing 2 different types is undefined in C.

Note that compilers that optimize better than GCC, say intel c++ which is 
10% - 30% faster for many of my codes, statistical odds it goes wrong is 
higher than GCC.

In assembler it could for example XOR just register ah, which is a 8 bits 
register and then further you compare register aex with another value.

So the other 24 bits of that register might have some random value.

In 64 bits it's even bigger problem also with gcc.
I write lots of 64 bits codes.

unsigned long long x;
If( x == 0 ) // undefined behaviour also in GCC

Probably for the same reason. Didn't figure out in assembler what's case 
there. Assuming same problem that it XORS some 32 bits value and compares 
with 64 bits in reality. It's a common mistake in codes mine. I have to 
fix this a lot regrettably.

What works for me is:

if( x == 0ULL ) // works

On Sat, 2 Jan 2016, Jonathan Wakely wrote:

> On 1 January 2016 at 16:03, Vincent Diepeveen wrote:
>>
>> If result returns integer it's ok.
>> If it returns a Long you are in trouble usually as then it has to compare
>> with
>>
>> 0L
>>
>> unsigned long or 64 bits unsigned:
>>
>> 0ULL
>
> Why is that a problem?
>



More information about the Gcc-help mailing list