develooper Front page | perl.perl5.porters | Postings from February 2000

Strange perls behaviour (a question)

From:
Sergey V. Kolychev
Date:
February 18, 2000 09:31
Subject:
Strange perls behaviour (a question)
Message ID:
Pine.LNX.3.96.1000218191007.24622A-100000@gw.al.lg.ua
Good day.

I got an interesting case with perl 5.004 i386 Linux Redhat 5.0
I have some xs module (Net::RawIP) and using 
the  following statement in xsub.
u_int32_t value = SvIV(sv) ,  very simple.
The weirdness is that perl makes a  difference from a variable 
that is hardcoded in the  script and one given to it by a shell as a
parameter.
1)
$a = 4294967295; # 2**32 -1
somexs($a);
In the xs I get unsigned int 4294967295.
2)
$a = $ARGV[0];
somexs($a);
./script.pl 4294967295
In the xs I get int of 0x7FFFFFFF.
3)
$a = ~0 - (~0 - $ARGV[0]);
somexs($a);
./script.pl 4294967295
In the xs I get unsigned int 4294967295.
------------
In all of these ways if I trying to print $a then perl prints 4294967295.

If somebody would like to answer ( I know you all are very busy people),
then please answer by e-mail. I am not in the list.

Have a nice day.

   ----------------------Alchevsk Linux User Group-----------------------
      I don't call, I don't cry , I don't apologize
      All will be gone like a apple tree's white smoke... (S.Esenin)
      http://www.ic.al.lg.ua/~ksv | e-mail: ksv@gw.al.lg.ua
      PGP key: finger ksv@gw.al.lg.ua




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About