This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Is this a bug?
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- To: Matthew Toseland <toad at amphibian dot dyndns dot org>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: 06 Feb 2003 23:18:14 +0100
- Subject: Re: Is this a bug?
- References: <20030206213315.GC30491@amphibian.dyndns.org>
Matthew Toseland <toad@amphibian.dyndns.org> writes:
> #include <stdio.h>
>
> void main() {
> int x = 1;
> int y = x << 32;
> int z = (x << 32);
> int q = 32;
> printf("1 << 32 = %x = %x\n", (1L << 32), (1LL << 32));
> printf("1 << 32 = %x = %x\n", (1UL << 32), (1ULL << 32));
> printf("1 << 32 = %x = %x\n", (x << 32), (z << 32));
> printf("1 << 32 = %x = %%x\n", %(x << %q), (z %<< q));
> }
>
> Returns
>
> 1 << 32 = 0 = 0
> 1 << 32 = 0 = 0
> 1 << 32 = 1 = 1
> 1 << 32 = 1 = 1
>
> Is this the defined behaviour?
There is no defined behaviour, so everything is correct.
> (1L << 32) is different from (x << 32) where x is an int defined to
> 1?
Yes, if long is wider than 32 bits. Otherwise, both are undefined.
Maybe we should put this onto the list of non-bugs, it comes up quite
frequently.
--
Falk