This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: typeof and bitfields
- From: Paul Schlie <schlie at comcast dot net>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Fri, 14 Jan 2005 10:33:33 -0500
- Subject: Re: typeof and bitfields
> From: Andreas Schwab <schwab@suse.de>
>> Paul Schlie <schlie@comcast.net> writes:
>> Wonder if the integer type/size that is allocated upon access, would be
>> more useful, consistent, and pertinent for typeof and sizeof to return.
>
> You can't apply sizeof to a bit-field member.
Merely meant that it would seem more useful for it to return the size of
the compatible temporary allocated if it were to be accessed, vs. being
undefined.
i.e.
int n, x:3 = -2;
x = ((n = sizeof(x)), x) + 1;
yielding n == 1, if a signed byte temporary was minimally allocated by the
compiler to store the bit-field value in to enable expression evaluation.
Thereby sizeof on a bit-field effectively returns the minimal size
compatible rvalue type allocated by the compiler if accessed.
As it would not seem to be inconsistent with:
Semantics
[#2] The sizeof operator yields the size (in bytes) of its
operand, 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 an integer. If the type of the
operand is a variable length array type, the operand is
evaluated; otherwise, the operand is not evaluated and the
result is an integer constant.
[#3] When applied to an operand that has type char, unsigned
char, or signed char, (or a qualified version thereof) the
result is 1. When applied to an operand that has array
type, the result is the total number of bytes in the
array.72 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.
[#4] The value of the result is implementation-defined, and
its type (an unsigned integer type) is size_t defined in the
<stddef.h> header.
[#5]
1. A principal use of the sizeof operator is in
communication with routines such as storage allocators
and I/O systems. A storage-allocation function might
accept a size (in bytes) of an object to allocate and
return a pointer to void. For example:
extern void *alloc(size_t);
double *dp = alloc(sizeof *dp);
The implementation of the alloc function should ensure
that its return value is aligned suitably for
conversion to a pointer to double.