Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Apr 2007 12:41:05 -0500
From:      Eric Anderson <anderson@freebsd.org>
To:        Andriy Gapon <avg@icyb.net.ua>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: strange bit-shifting
Message-ID:  <461291B1.2070303@freebsd.org>
In-Reply-To: <46128D47.50109@icyb.net.ua>
References:  <46128D47.50109@icyb.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On 04/03/07 12:22, Andriy Gapon wrote:
> $ cat test_shl.c
> #include <stdint.h>
> #include <stdio.h>
> 
> int main()
> {
>         uint64_t l;
> 
>         l = 0;
>         l--;
>         printf("%.16lX\n", l);
>         l <<= 64;
>         printf("%.16lX\n", l);
>         return 0;
> }
> 
> $ cc test_shl.c -o test_shl
> test_shl.c: In function `main':
> test_shl.c:11: warning: left shift count >= width of type
> $ ./test_shl
> FFFFFFFFFFFFFFFF
> FFFFFFFFFFFFFFFF
> $ uname -srm
> FreeBSD 6.2-RELEASE-p2 amd64
> $ gcc -v
> Using built-in specs.
> Configured with: FreeBSD/amd64 system compiler
> Thread model: posix
> gcc version 3.4.6 [FreeBSD] 20060305
> 
> What gives ? It looks like shift is actually done not by specified
> number of bits but by that number modulo 64.
> Please also mind that the same thing happens if I use a variable instead
> of a constant in that expression.
> 


I see the same thing on -CURRENT.  I was doing something like:

uint64_t l;
l = 1 << 40;

but instead did:
l = (1 << 30) * 1024;

which works fine.

This was on i386.

Eric




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?461291B1.2070303>