perl and network addresses

Kevin D. Clark kclark at mtghouse.com
Mon Apr 3 17:46:00 EDT 2006


Stephen Ryan writes:

> Ooh, here's something interesting.  I first tried a test with constants,
> and got the warning: left shift count >= width of type" out of gcc.
> Then I rewrote the thing to use a loop, and I got correct results out of
> it.  (This is all on an Athlon64X2.)
>
> When you described getting the same results for 0 and 32, I tried it
> again on my wife's laptop, a Celeron M, and got the same results you
> did; just out of curiosity, I looked it up, and gcc generates a 'sall'
> instruction to do the actual bit-shift, which on the 80386, PIII and
> Celeron M (according to Intel's documentation, your test, and my test,
> respectively) all ignore everything but the low 5 bits on the shift
> count.  The 64-bit Athlon64 apparently doesn't, though, even though I'm
> supposedly running in 32-bit compatibility mode.  Huh.
>
> Yet another demonstration of the dangers of of assuming specific
> bit-sizes for int, I suppose.

Another thing to be aware of (but which hasn't come up...yet...in this
thread) is that all of the test code that I see here uses signed
integers for the bit operations (~ << etc.).  The C spec. specifically
states that the results of such expressions is system dependent (and
hence unportable).

That warning message you saw was gcc doing an OK job warning you of a
possible problem.  When you added the loop you bamboozled the compiler,
but the underlying issue (however small) still remained.

Just another compiler guy...

--kevin
-- 
GnuPG ID: B280F24E                     And the madness of the crowd
alumni.unh.edu!kdc                     Is an epileptic fit
                                       -- Tom Waits




More information about the gnhlug-discuss mailing list