Re: The result of 1 << 32
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 09:44:10 +0000
Walter Roberson wrote:
In article <slrndm762i.o4v.jmabel@xxxxxxxxxxxxx>, Jordan Abel <jmabel@xxxxxxxxxx> wrote:
On 2005-10-29, mrby <bianying@xxxxxxxxx> wrote:
Why 1<<i and 1<<32 get different result? I had thought both of them would get 0x0.
A theory: the 1<<32 is calculated at compile time [and the compiler itself is smart enough to do this] while the 1<<i value is calculated at runtime - now, if your processor's LSH instruction only accepts a 5-bit immediate operand.
According to the standard, shifting by a number greater than or equal to the field width is undefined.
I don't have my reference material here, but I seem to recall that constant calculations are supposed to be done "as if" they were done at run-time. Possibly that only applied to calculations in preprocessor expressions.
If my recollection is correct, then even though the shift behaviour is undefined, would it not be required to be consistant?
No, the result of undefined behaviour is not required to be consistent. If undefined behaviour had to be consistent then that would effectively mean having to detect buffer overruns, otherwise how could it provide consistent behaviour on the undefined behaviour caused by writing beyond the end of a buffer?
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
- References:
- The result of 1 << 32
- From: mrby
- Re: The result of 1 << 32
- From: Jordan Abel
- The result of 1 << 32
- Prev by Date: Re: reading from a text file
- Next by Date: Re: Pse, help me to understand this code
- Previous by thread: Re: The result of 1 << 32
- Next by thread: Re: The result of 1 << 32
- Index(es):
Relevant Pages
|