in reply to CHAR_BIT != 8

C99 says that CHAR_BIT must be at least 8; POSIX says it must be exactly 8; on Windows it's 8. That's about all the platforms it's worth caring about.

Some DSPs use CHAR_BIT=16 or CHAR_BIT=32, but they're never going to run Perl anyway.

How to get it? This is cheating I'm sure...

use strict; use warnings; my $char_bit; open my $fh, "<", "/usr/include/limits.h"; while (<$fh>) { ($char_bit = $1, last) if /^#\s*define\s*CHAR_BIT\s*([0-9]+)/; } print "$char_bit\n";

It's the kind of detail you might expect to be provided by Config, but no such luck :-(

Update: meh... I wasn't looking hard enough...

use strict; use warnings; use Config; print "$Config{charbits}\n";
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: CHAR_BIT != 8
by ribasushi (Pilgrim) on Mar 08, 2013 at 16:13 UTC
    Oh indeed. New Config piece starting from 5.12, this is why I didn't see it.