Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cf0fb8bf
Commit
cf0fb8bf
authored
Jul 23, 1998
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document the 'p' format character.
Clean up some of the markup.
parent
c457ca7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
Doc/lib/libstruct.tex
Doc/lib/libstruct.tex
+16
-7
No files found.
Doc/lib/libstruct.tex
View file @
cf0fb8bf
...
...
@@ -55,6 +55,7 @@ and Python values should be obvious given their types:
\lineiii
{
f
}{
float
}{
float
}
\lineiii
{
d
}{
double
}{
float
}
\lineiii
{
s
}{
char[]
}{
string
}
\lineiii
{
p
}{
char[]
}{
string
}
\end{tableiii}
A format character may be preceded by an integral repeat count; e.g.
\
...
...
@@ -63,7 +64,7 @@ the format string \code{'4h'} means exactly the same as \code{'hhhh'}.
Whitespace characters between formats are ignored; a count and its
format must not contain whitespace though.
For the
\c
ode
{
's'
}
format character, the count is interpreted as the
For the
\c
haracter
{
s
}
format character, the count is interpreted as the
size of the string, not a repeat count like for the other format
characters; e.g.
\code
{
'10s'
}
means a single 10-byte string, while
\code
{
'10c'
}
means 10 characters. For packing, the string is
...
...
@@ -72,7 +73,15 @@ For unpacking, the resulting string always has exactly the specified
number of bytes. As a special case,
\code
{
'0s'
}
means a single, empty
string (while
\code
{
'0c'
}
means 0 characters).
For the
\code
{
'I'
}
and
\code
{
'L'
}
format characters, the return
The
\character
{
p
}
format character can be used to encode a Pascal
string. The first byte is the length of the stored string, with the
bytes of the string following. If count is given, it is used as the
total number of bytes used, including the length byte. If the string
passed in to
\function
{
pack()
}
is too long, the stored representation
is truncated. If the string is too short, padding is used to ensure
that exactly enough bytes are used to satisfy the count.
For the
\character
{
I
}
and
\character
{
L
}
format characters, the return
value is a Python long integer.
By default, C numbers are represented in the machine's native format
...
...
@@ -91,7 +100,7 @@ according to the following table:
\lineiii
{
!
}{
network (= big-endian)
}{
standard
}
\end{tableiii}
If the first character is not one of these,
\c
ode
{
'@'
}
is assumed.
If the first character is not one of these,
\c
haracter
{
@
}
is assumed.
Native byte order is big-endian or little-endian, depending on the
host system (e.g. Motorola and Sun are big-endian; Intel and DEC are
...
...
@@ -105,16 +114,16 @@ for any type (so you have to use pad bytes); short is 2 bytes; int and
long are 4 bytes. Float and double are 32-bit and 64-bit IEEE floating
point numbers, respectively.
Note the difference between
\c
ode
{
'@'
}
and
\code
{
'='
}
: both use native
Note the difference between
\c
haracter
{
@
}
and
\character
{
=
}
: both use native
byte order, but the size and alignment of the latter is standardized.
The form
\c
ode
{
'!'
}
is available for those poor souls who claim they
The form
\c
haracter
{
!
}
is available for those poor souls who claim they
can't remember whether network byte order is big-endian or
little-endian.
There is no way to indicate non-native byte order (i.e. force
byte-swapping); use the appropriate choice of
\c
ode
{
'<'
}
or
\c
ode
{
'>'
}
.
byte-swapping); use the appropriate choice of
\c
haracter
{
<
}
or
\c
haracter
{
>
}
.
Examples (all using native byte order, size and alignment, on a
big-endian machine):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment