Previous Table of Contents "New C Standard" commentary
1118
The
1119
The
1120 The size is determined from the type of the operand.
1121 The result is an integer.
1122 If the type of the operand is a variable length array type, the operand is evaluated;
1123 otherwise, the operand is not evaluated and the result is an integer constant.
1124
When applied to an operand that has type
1125 When applied to an operand that has array type, the result is the total number of bytes in the array.85)
1126 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.
1127
The value of the result is implementation-defined, and its type (an
unsigned integer type) is
1128
EXAMPLE 1
A principal use of the
extern void *alloc(size_t);
double *dp = alloc(sizeof *dp);
The implementation of the
1129
EXAMPLE 2
Another use of the
sizeof array / sizeof array[0]
1130 EXAMPLE 3 In this example, the size of a variable length array is computed and returned from a function:
#include
size_t fsize3(int n)
{
char b[n+3]; // variable length array
return sizeof b; // execution time sizeof
}
int main()
{
size_t size;
size = fsize3(10); // fsize3 returns 13
return 0;
}
1131
85) When applied to a parameter declared to have array or function
type, the
1132
Forward references:
common definitions
Next
Created at: 2008-01-30 02:39:42
The text from WG14/N1256 is copyright © ISO