On Windows, how can I check whether my Perl installation is 32 or 64 bit?
If you want to check if it uses 32-bit integers or 64-bit integers, use the following:
perl -V:ivsize # use Config; say $Config{ivsize}
- If the returned value is 4, your Perl uses 32-bit integers.
- If the returned value is 8, your Perl uses 64-bit integers.
See also: Answer to "What is the perl equivalent of MAX_INT?"
If you want to check if it uses 32-bit pointers or 64-bit pointers, use the following:
perl -V:ptrsize # use Config; say $Config{ptrsize}
- If the returned value is 4, your Perl can address 4 GiB of RAM.
- If the returned value is 8, your Perl can address "unlimited" RAM.
If you want to check if it's a 32-bit program or a 64-bit program, use the following:
perl -V:archname # use Config; say $Config{archname}
- If the returned value includes
x86_64
, it's a 64-bit process. - If the returned value includes
x86
(but notx86_64
), it's a 32-bit process.
This value is also included in the output of perl -v
.
Note: You shouldn't be checking use64bitint
or use64bitall
as these indicate what parameters were passed to Configure
rather than provide information about what is actually being used.
I'm reading the question to ask if Perl is compiled 64 bit, not if Windows or the CPU is.
Perl can be configured to use varying degrees of 64 bit-ness. You can look this up using the Config module.
To check if Perl is compiled to use 64 bit integers, you can look at the use64bitint
entry in Config.
use Config;
print $Config{use64bitint};
define
indicates yes.
There is also...
use64bitall
meaning perl will be compiled to use all the 64 bit-ness it can, including 64 bit pointers allowing you to access more than 2 gigs of memory.ivsize
indicating how many bytes Perl will use to store an integer, 8 indicates 64 bit.ptrsize
is how many bits Perl will use to store pointers which allows you to use more than 2 gigs of memory per process, 8 indicates 64 bit.
Common Config variables and their values can be seen in perl -V
(note the capital V). Their definitions can be found with perldoc Config
.
Note, you can compile Perl to use 64 bit integers regardless of whether your operating system or CPU is 32 or 64 bit. On a 32 bit CPU, Perl will use a type other than "integer" to store numbers, probably "long integer".
log(~0 +1)/log(2)
works because :
- ~0 is "bitwise not zero" -> UINT_MAX
- UINT_MAX is either 2^32-1 or 2^64-1, depending on the architecture (or compile options)
- log(2^32)/log(2) = 32 and log(2^64)/log(2) = 64, by design.
So basically this command order perl to say how many bits have its UINT_MAX.
$ perl -e "print log(~0 +1)/log(2)"
32
$ perl -V:archname
archname='MSWin32-x86-multi-thread';
Just check the version/build:
perl -v
And I got:
This is perl, v5.8.8 built for msys-64int
Copyright 1987-2006, Larry Wall
...
64int
in perl -v
's output does NOT indicate a 64-bit program. While perl -v
would normally tell you if it's a 32-bit or 64-bit process (by including x86
or x86_64
), you showed that it doesn't work (it doesn't tell you either way) for msys
. –
Olag Please consider the less computationally expensive:
$is32bit = ~0==0xFFFFFFFF ? 1:0;
© 2022 - 2024 — McMap. All rights reserved.