blob: 882080ecdbb0715cc7f610a9cfc5914f4ea9797b [file] [log] [blame] [edit]
[open,refpage='sizeofOperator',desc='Sizeof Operator',type='freeform',spec='clang',anchor='operators-sizeof',xrefs='']
--
The `sizeof` operator yields the size (in bytes) of its operand, including
any <<alignment-of-types,padding bytes needed for alignment>>, which may be
an expression or the parenthesized name of a type.
The size is determined from the type of the operand.
The result is of type `size_t`.
If the type of the operand is a variable length array^19^ type, the operand
is evaluated; otherwise, the operand is not evaluated and the result is an
integer constant.
[19] Variable length arrays are <<restrictions-variable-length,not supported
in OpenCL C>>.
When applied to an operand that has type `char` or `uchar`, the result is 1.
When applied to an operand that has type `short`, `ushort`, or `half` the
result is 2.
When applied to an operand that has type `int`, `uint` or `float`, the
result is 4.
When applied to an operand that has type `long`, `ulong` or `double`, the
result is 8.
When applied to an operand that is a vector type, the result^20^ is number of
components * size of each scalar component.
When applied to an operand that has array type, the result is the total
number of bytes in the array.
When applied to an operand that has structure or union type, the result is
the total number of bytes in such an object, including internal and trailing
padding.
The `sizeof` operator shall not be applied to an expression that has
function type or an incomplete type, to the parenthesized name of such a
type, or to an expression that designates a bit-field struct member^21^.
[20] Except for 3-component vectors whose size is defined as 4 * size of each
scalar component.
[21] Bit-field struct members are <<restrictions-bitfield, not supported in
OpenCL C>>.
The behavior of applying the `sizeof` operator to the `bool`, `image2d_t`,
`image3d_t`, `image2d_array_t`, `image2d_depth_t`, `image2d_array_depth_t`,
`image1d_t`, `image1d_buffer_t` or `image1d_array_t`, `sampler_t`,
`clk_event_t`, `queue_t` and `event_t` types is implementation-defined.
--