in reply to word size

You might find the information available from Config useful. Here's a list of keys with 'size' in the the name:

use Config;; printf "$_ => %s", $Config{ $_ }||'n/a' for grep /size/i, keys %Config +;; charsize => 1 d_chsize => define doublesize => 8 fpossize => 8 gidsize => 4 i16size => 2 i32size => 4 i64size => 8 i8size => 1 intsize => 4 ivsize => 4 longdblsize => 10 longlongsize => 8 longsize => 4 lseeksize => 8 nvsize => 8 ptrsize => 4 shortsize => 2 sig_size => 27 sizesize => 4 sizetype => size_t socksizetype => int ssizetype => int u16size => 2 u32size => 4 u64size => 8 u8size => 1 uidsize => 4 uvsize => 4

intsize & ivsize are probably the most relevant for your purpose.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: word size
by collin (Scribe) on Sep 08, 2005 at 05:00 UTC
    Ahh...but how much fun would that be? This was, after all, meant to be a CUFP; something that originated in some assembly I was working on. How often do you see the bit operations put to use? :o)
Re^2: word size
by ambrus (Abbot) on Sep 08, 2005 at 21:28 UTC

    The problem is, that all those sizes are in bytes, not bits. I'm not sure how you can compute the size of something in bits using Config, as it doesn't tell the number of bits in characters. Maybe you could use something like ivsize/i32size*32.

      Hmm. Now I know there have been machines with 6-bit bytes, and (maybe) 9-bit bytes, in the dark distant past, but I'm not aware of any remotely modern cpu that doesn't use 8-bit bytes?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

        For a current machine (one on which Perl runs) 6 bit bytes are surely impossible, and I belive that 9 bit bytes don't exist any more: everyone works in multiples of 8 bytes. I think that this dominance of 8 bits is a consequence of the internet. It would be even more difficult to transfer binary data (like the IP and TCP header for example) from one machine to the other than now if they differed not only in word size and byte order, but this way. Also, even without the internet, all current hardware, such hard disks, video cards, work with multiples of 8 bits.

        However, there can be (rare) machines where the char can be 32 or 16 bits. This can be either because the CPU doesn't handle 8-bit numbers efficently; or it could be because it's impossible to implement C on that CPU with char being 8 bits for some other obscure reason. (In this case, sizeof(char) will still be 1, because sizeof, malloc, and other C functions would count in units of chars.)