|
From: Tom H. <to...@co...> - 2005-10-18 07:44:11
|
In message <Pin...@jd...>
Igmar Palsenberg <mai...@jd...> wrote:
>> int main()
>> {
>> int uninit;
>
> uninit is undefined here.
>
>> int two = 2;
>>
>> uninit *= two;
>
> this is uninit = uninit * 2;
>
> As far as I can tell, the whole of uninit is undefined, so is the result
> of the multiplication.
>
>> if(!(uninit & 1)) // there should be no error here
>> {
>
> uninit still contains random data. Why shouldn't it give errors ?
He is only looking at the lowest bit and as he has doubled it that
bit is guaranteed to be zero and well defined.
Multiplying by two is after equivalent to a left shift by one and
such a shift is guaranteed to shift in a zero and hence make the
bottom bit well defined.
Tom
--
Tom Hughes (to...@co...)
http://www.compton.nu/
|