diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-10-06 19:03:51 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-10-06 22:20:19 +0900 |
commit | 7b8d472100332c77bb47a2e4834459c4a625d109 (patch) | |
tree | 882aaa4839eb0759fe86a8233b3ee4f297cceb83 | |
parent | 7db4ce13ed051bc422c5db594bb41edbaeb1ae35 (diff) | |
download | ruby-7b8d472100332c77bb47a2e4834459c4a625d109.tar.gz |
[DOC] Fix platform-dependent directives and modifiers
* 'j' and 'J' are not pointer directives.
* size of 'j' and 'J' are platform-dependent, may not be 64-bit.
* mention corresponding C types when native-size modifier is added.
Co-Authored-By: BurdetteLamar <burdettelamar@yahoo.com>
-rw-r--r-- | doc/packed_data.rdoc | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/doc/packed_data.rdoc b/doc/packed_data.rdoc index 05d9ab758a..b1b1e357f9 100644 --- a/doc/packed_data.rdoc +++ b/doc/packed_data.rdoc @@ -214,18 +214,16 @@ for one element in the input or output array. s.unpack('I*') # => [67305985, 4244504319] -==== Pointer Directives - -- <tt>'j'</tt> - 64-bit pointer-width signed integer, - native-endian (like C <tt>intptr_t</tt>): +- <tt>'j'</tt> - Pointer-width signed integer, native-endian + (like C <tt>intptr_t</tt>): s = [67305985, -50462977].pack('j*') # => "\x01\x02\x03\x04\x00\x00\x00\x00\xFF\xFE\xFD\xFC\xFF\xFF\xFF\xFF" s.unpack('j*') # => [67305985, -50462977] -- <tt>'j'</tt> - 64-bit pointer-width unsigned integer, - native-endian (like C <tt>uintptr_t</tt>): +- <tt>'j'</tt> - Pointer-width unsigned integer, native-endian + (like C <tt>uintptr_t</tt>): s = [67305985, 4244504319].pack('J*') # => "\x01\x02\x03\x04\x00\x00\x00\x00\xFF\xFE\xFD\xFC\x00\x00\x00\x00" @@ -251,20 +249,19 @@ for one element in the input or output array. ==== Modifiers for \Integer Directives -For directives in -<tt>'i'</tt>, -<tt>'I'</tt>, -<tt>'s'</tt>, -<tt>'S'</tt>, -<tt>'l'</tt>, -<tt>'L'</tt>, -<tt>'q'</tt>, -<tt>'Q'</tt>, -<tt>'j'</tt>, and -<tt>'J'</tt>, -these modifiers may be suffixed: - -- <tt>'!'</tt> or <tt>'_'</tt> - Underlying platform’s native size. +For the following directives, <tt>'!'</tt> or <tt>'_'</tt> modifiers may be +suffixed as underlying platform’s native size. + +- <tt>'i'</tt>, <tt>'I'</tt> - C <tt>int</tt>, always native size. +- <tt>'s'</tt>, <tt>'S'</tt> - C <tt>short</tt>. +- <tt>'l'</tt>, <tt>'L'</tt> - C <tt>long</tt>. +- <tt>'q'</tt>, <tt>'Q'</tt> - C <tt>long long</tt>, if available. +- <tt>'j'</tt>, <tt>'J'</tt> - C <tt>intptr_t</tt>, always native size. + +Native size modifiers are silently ignored for always native size directives. + +The endian modifiers also may be suffixed in the directives above: + - <tt>'>'</tt> - Big-endian. - <tt>'<'</tt> - Little-endian. |