syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Is there anything in %Config that will tell me the sizeof(long) on the compiler that built perl ?

$Config{use64bitint} won't, nor will $Config{intsize}. $Config{longsize} looks a likely candidate. On the only 'perl -V' I have for perl built with a 64-bit compiler, it reports 8 - but is it a reliable indicator ?

Cheers,
Rob

Replies are listed 'Best First'.
Re: Perl and 64-bit compilers
by liverpole (Monsignor) on Feb 18, 2007 at 01:55 UTC
    Hi syphilis,

    You've read the documentation for Config, I'm sure:

    longsize From intsize.U: This variable contains the value of the LONGSIZE symbol, which indicates to the C program how many bytes there are in a long.

    That seems pretty clear to me, especially the "how many bytes there are in a long", which is what you want (sizeof(long)).

    Do you have some doubts that that is correct?


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Do you have some doubts that that is correct?

      Well ... the 'perl -V' that I was looking at is for a (Debian/testing) Linux/x86_64 machine. I expected that 'intsize' would also be 8, but it's only 4. That made me wonder about the reliability of what %Config was telling me in this regard.

      Anyway, I gather from the tone of your response, that this info is reliable - which is what I needed to know. Thanks for clearing that up for me.

      (I don't believe there's any reason that an int and a long have to be the same size ... it's just that I didn't expect them to be different ... and that's what raised the doubt in my mind :-)

      Cheers,
      Rob
            "I don't believe there's any reason that an int and a long have to be the same size ... it's just that I didn't expect them to be different"

        I've always heard about "C" (and perhaps you have as well) that "the only thing you can be sure is that a long isn't any smaller than a short.  (Which certainly doesn't narrow things down very much!)

        However, I would have expected the same, that intsize would have been 8.  So I can fully see why you'd have questions regarding the veracity of the documentation for longsize.

        By the way, I didn't mean to mislead you -- I'm not in any way an authority on the Config module.  I did just now look at the source for Config, but as it contained the results of running Configure, the values for the particular architecture were already hardcoded into it.  So I'd be asking the same questions you are.

        Here's a thought:  trying downloading the tarball for Config and installing it manually.  Then you can look at the Configure script that comes with it, and make sure it's simply reporting the appropriate thing from the perspective of the "C" compiler.

        Update:  I just now saw your response (below) to ambrus's suggestion, where you say you don't have direct access to the machine.  So you probably won't be able to inspect the sourcecode. :-(


        s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Perl and 64-bit compilers
by ambrus (Abbot) on Feb 18, 2007 at 12:13 UTC

    You can also try length(pack("l!")).

      I therefore leap to the conclusion that length(pack("i")) will give me the same as $Config{intsize}.

      If that's the case, then I find it a little confusing that 'perldoc -f pack' tells me that the 'int' may be even larger than the 'long', yet %Config is telling me that it's smaller (wrt the particular Linux x86_64 box in question - to which I don't have direct access, btw).

      Thanks for alerting me to the alternative.

      Cheers,
      Rob

        I think you misunderstand what pack tells you. Look. The pack templates are:

        i - native C int l - always 32 bits (nicknamed "long") l! - native C long
        The native long is always at least as large as the native int. The native int could potentially be larger then 32 bits. On typical systems, however, an int is 32 bits long and long is either 32 or 64 bits.