Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: reliably test integer size for portable bit-fiddling?

by BrowserUk (Patriarch)
on Dec 08, 2014 at 20:00 UTC ( [id://1109633]=note: print w/replies, xml ) Need Help??


in reply to reliably test integer size for portable bit-fiddling?

Use Config and check the ivsize key:

C:\test>perl -MConfig -E"say $Config{ ivsize }" 8 C:\test>\perl32\bin\perl -MConfig -le"print $Config{ ivsize }" 4

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: reliably test integer size for portable bit-fiddling?
by wollmers (Scribe) on Dec 08, 2014 at 20:39 UTC

    Thx, but if I can avoid loading Config, and the dependency on it, then pure Perl wins.

    root@raspberry2:/home/helmut# time perl -MConfig -E 'print $Config{ivs +ize};' 8 real 0m0.177s user 0m0.160s sys 0m0.010s root@raspberry2:/home/helmut# time perl -e 'print length(pack('j', -1 +))*8;' 64 real 0m0.028s user 0m0.020s sys 0m0.000s
      Config is a core module, so is always available.

      Your code seems to work fine here:

      C:\test>\perl32\bin\perl -e"print length(pack('j', -1))*8;" 32 C:\test>perl -e"print length(pack('j', -1))*8;" 64

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      Config is part of Perl, and is Pure Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1109633]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-20 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found