diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 1999-02-10 02:04:52 +0200 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-15 06:26:39 +0000 |
commit | ef54e1a45e68bbd668c909c97e266f20578d5516 (patch) | |
tree | a96ebdb7f26c3b0299b7fa25241acb35de121905 /pod | |
parent | 9ef261b5e9ba232556e09d48dcf0e3964298f8f6 (diff) | |
download | perl-ef54e1a45e68bbd668c909c97e266f20578d5516.tar.gz |
support native integers, pack("L_",...) etc. (via private mail)
Message-Id: <199902092204.AAA29065@alpha.hut.fi>
Subject: the "packnative" patch
p4raw-id: //depot/perl@2936
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perldelta.pod | 5 | ||||
-rw-r--r-- | pod/perldiag.pod | 5 | ||||
-rw-r--r-- | pod/perlfunc.pod | 52 |
3 files changed, 62 insertions, 0 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod index f64a1da5f4..7f944c24b4 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -144,6 +144,11 @@ Note that the behavior of: is unchanged (it continues to leave the file empty). +=head2 pack() format modifier '_' supported + +The new format type modifer '_' is useful for packing and unpacking +native shorts, ints, and longs. See L<perlfunc/"pack">. + =head1 Supported Platforms =over 4 diff --git a/pod/perldiag.pod b/pod/perldiag.pod index eb84876d4e..6594e0cae9 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -51,6 +51,11 @@ no useful value. See L<perlmod>. (F) The "use" keyword is recognized and executed at compile time, and returns no useful value. See L<perlmod>. +=item '_' allowed only after types %s + +(F) The '_' is allowed in pack() and unpack() only after certain types. +See L<perlfunc>. + =item % may only be used in unpack (F) You can't pack a string by supplying a checksum, because the diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index d5b631bb0a..07e2361def 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -2591,6 +2591,58 @@ C<"P"> is C<undef>. =item * +The integer types C<"s">, C<"S">, C<"l">, and C<"L"> may be +immediately followed by a C<"_"> to signify a native short or long--as +you can see from above for example a bare C<"l"> does mean exactly 32 +bits, the native C<long> (as seen by the local C compiler) may be +larger. This is an issue mainly in 64-bit platforms. + +C<"i_"> and C<"I_"> also work but only because of completeness; +they are identical to C<"i"> and C<"I">. + +The actual size (in bytes) of native shorts, ints, and longs on +the platform where Perl was built are available from L<Config>: + + use Config; + print $Config{shortsize}, "\n"; + +=item * + +The integer formats C<"s">, C<"S">, C<"i">, C<"I">, C<"l">, and C<"L"> +are inherently non-portable between processors and operating systems +because they obey the native byteorder and endianness. For example a +4-byte integer 0x12345678 (305419896 decimal) be ordered natively +(arranged in and handled by the CPU registers) into bytes as + + 0x12 0x34 0x56 0x78 # big-endian + 0x78 0x56 0x34 0x12 # little-endian + +The names `big-endian' and `little-endian' are joking references to +the classic "Gulliver's Travels" (via the paper "On Holy Wars and a +Plea for Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980) and +the egg-eating habits of the lilliputs. + +Some systems may even have weird byte orders such as + + 0x56 0x78 0x12 0x34 + 0x34 0x12 0x78 0x56 + +You can see your system's preference with + + print join(" ", map { sprintf "%#02x", $_ } + unpack("C*",pack("L",0x12345678))), "\n"; + +The actual byteorder on the platform where Perl was built are available +from L<Config>: + + use Config; + print $Config{byteorder}, "\n"; + +If you want portable integers use the formats C<"n">, C<"N">, C<"v">, and +"V", their byte endianness and size is known. + +=item * + Real numbers (floats and doubles) are in the native machine format only; due to the multiplicity of floating formats around, and the lack of a standard "network" representation, no facility for interchange has been |