sizeof(7): miscellaneous edits
Suggested by: pstef Reviewed by: imp, pstef (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D37683
This commit is contained in:
parent
57bee0817f
commit
9e0d976d95
@ -34,17 +34,38 @@ operator
|
|||||||
.br
|
.br
|
||||||
.Nm Vt expression
|
.Nm Vt expression
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The size of primitive data types in C may differ
|
The
|
||||||
|
.Nm
|
||||||
|
operator yields the size of its operand.
|
||||||
|
The
|
||||||
|
.Nm
|
||||||
|
operator cannot be applied to incomplete types and expressions
|
||||||
|
with incomplete types (e.g.
|
||||||
|
.Vt void ,
|
||||||
|
or forward-defined
|
||||||
|
.Vt struct foo ),
|
||||||
|
and function types.
|
||||||
|
.Pp
|
||||||
|
The size of primitive (non-derived) data types in C may differ
|
||||||
across hardware platforms and implementations.
|
across hardware platforms and implementations.
|
||||||
|
They are defined by corresponding Application Binary Interface (ABI)
|
||||||
|
specifications, see
|
||||||
|
.Xr arch 7
|
||||||
|
for details about ABI used by
|
||||||
|
.Fx .
|
||||||
It may be necessary or useful for a program to be able
|
It may be necessary or useful for a program to be able
|
||||||
to determine the storage size of a data type or object.
|
to determine the storage size of a data type or object
|
||||||
|
to account for the platform specifics.
|
||||||
.Pp
|
.Pp
|
||||||
The unary
|
The unary
|
||||||
.Nm
|
.Nm
|
||||||
operator yields the storage size of an expression or
|
operator yields the storage size of an expression or
|
||||||
data type in
|
data type in
|
||||||
.Em char sized units .
|
.Em char sized units
|
||||||
As a result, 'sizeof(char)' is always guaranteed to be 1.
|
(C language bytes).
|
||||||
|
As a result,
|
||||||
|
.Ql sizeof(char)
|
||||||
|
is always guaranteed to be 1.
|
||||||
(The number of bits per
|
(The number of bits per
|
||||||
.Vt char
|
.Vt char
|
||||||
is given by the
|
is given by the
|
||||||
@ -72,8 +93,7 @@ on an ILP32 vs. an LP64 system:
|
|||||||
.Pp
|
.Pp
|
||||||
When applied to a simple variable or data type,
|
When applied to a simple variable or data type,
|
||||||
.Nm
|
.Nm
|
||||||
returns the storage size of the data type of the
|
returns the storage size of the data type of the object:
|
||||||
object:
|
|
||||||
.Bl -column -offset indent \
|
.Bl -column -offset indent \
|
||||||
".Li sizeof(struct flex)" ".Sy Result (ILP32)" ".Sy Result (LP64)"
|
".Li sizeof(struct flex)" ".Sy Result (ILP32)" ".Sy Result (LP64)"
|
||||||
.It Sy Object or type \
|
.It Sy Object or type \
|
||||||
@ -128,7 +148,7 @@ platforms, as they are based on character units.
|
|||||||
.Pp
|
.Pp
|
||||||
When applied to a struct or union,
|
When applied to a struct or union,
|
||||||
.Nm
|
.Nm
|
||||||
returns the total number of units in the object,
|
returns the total number of bytes in the object,
|
||||||
including any internal or trailing padding used to
|
including any internal or trailing padding used to
|
||||||
align the object in memory.
|
align the object in memory.
|
||||||
This result may thus be larger than if the storage
|
This result may thus be larger than if the storage
|
||||||
@ -251,8 +271,10 @@ if ((buf = malloc(BUFSIZ)) == NULL) {
|
|||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
In that case, the operator will return the storage
|
In that case, the operator will return the storage
|
||||||
size of the pointer ('sizeof(char *)'), not the
|
size of the pointer (
|
||||||
allocated memory!
|
.Ql sizeof(char *)
|
||||||
|
), not the
|
||||||
|
allocated memory.
|
||||||
.Pp
|
.Pp
|
||||||
.Nm
|
.Nm
|
||||||
determines the
|
determines the
|
||||||
|
Loading…
Reference in New Issue
Block a user