Again: help ! why is evaluating oddly ? 
Author Message
 Again: help ! why is evaluating oddly ?

Ack ! Is perl bit shifting broken ?

$bar = (0x80000000 |((4&127)<<16)|(102<<8)|126);
print STDOUT "$bar\n";
2147772030

It should be -2147195266.

In 'C' this evaluates okay....

printf("%d\n",
    (0x80000000  |((4&127)<<16)|(102<<8)|126));

-2147195266

Even "lowly tcl" (heh.) can do it:

tcl>set foo [expr (0x80000000 |((4&127)<<16)|(102<<8)|126)]
-2147195266

What am I doing wrong ?
(INT_MIN is  -2147483646)

This makes it impossible to "roll your own" ioctl.h on an
AIX box... (without hard coding values)

I get the same results on AIX, SunOS 4.1.3 and Linux...

Sure would like to do:
    ioctl(NS, &FIONBIO, 1);
instead of my ugly:
    ioctl(NS, -2147195266, 1);

Thanks,

--
Kerry



Mon, 28 Apr 1997 22:23:13 GMT  
 Again: help ! why is evaluating oddly ?

:
:Ack ! Is perl bit shifting broken ?
:
:$bar = (0x80000000 |((4&127)<<16)|(102<<8)|126);
:print STDOUT "$bar\n";
:2147772030
:
:It should be -2147195266.
:
:In 'C' this evaluates okay....
:
:printf("%d\n",
:    (0x80000000  |((4&127)<<16)|(102<<8)|126));
:
:-2147195266
:
:Even "lowly tcl" (heh.) can do it:
:
:tcl>set foo [expr (0x80000000 |((4&127)<<16)|(102<<8)|126)]
:-2147195266
:
:What am I doing wrong ?
:(INT_MIN is  -2147483646)

Perl isn't use signed 32 two's complement bit integers, which you
seem to be assuming.  It's using doubles.

Even 'use integer' doesn't help.

:This makes it impossible to "roll your own" ioctl.h on an
:AIX box... (without hard coding values)
:
:I get the same results on AIX, SunOS 4.1.3 and Linux...
:
:Sure would like to do:
:    ioctl(NS, &FIONBIO, 1);
:instead of my ugly:
:    ioctl(NS, -2147195266, 1);

Oh my.  That's bad.  

Guys, we really do need

    use Ioctl;

--tom
--

Living on Earth may be expensive, but it includes an annual free trip
around the Sun.



Mon, 28 Apr 1997 23:24:46 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help, why is this evaluating oddly ?

2. Help Wanted: Parsing data from oddly formatted files

3. numbers & strings again (and again and again)

4. Simple IF statement evaluating False -- why?

5. Why Perl Again ?

6. why dereference and then pass reference again on -textvariable option

7. newbie-perl or why am i blind to this simple

8. Why I am glad I know perl

9. Why am I dumping core???

10. ? Now I am reaaly perplexed, Why doesn't (INDEX) work

11. why am I having problems with mkdir

12. Why am I getting an undefined subroutine error?

 

 
Powered by phpBB® Forum Software