Article View: comp.std.c
Article #4861Bit-field sizes
From: Thad Smith
Date: Wed, 06 Mar 1996 06:49
Date: Wed, 06 Mar 1996 06:49
28 lines
1674 bytes
1674 bytes
Can the size of a bit-field, measured in bits, exceed the size of an int? The description of bit-fields describes it as an integral type with a (programmer-)specified number of bits, not specifically constrained in size. ANSI Classic section 3.2.1.1 says, however, that bit-fields are promoted to either int or unsigned int. This would seem to prohibit promoting a large bit-field to a long. If so, why was this constraint imposed? Secondly, is the storage unit within which bit-fields are allocated constrained to be a single size or can it vary, depending on the size of the bit fields? I see nothing in the standard prohibiting different size storage units for bit-fields. Also bit-fields are explicitly allowed to span multiple storage units, at least if the bit-field is not the first in a structure (the use of the word "may" makes the requirement for the first bit-field ambiguous with regard to storage in a single unit). If different size storage units are allowed or any bit-field is allowed to span multiple units, the size of a struct containing bit-fields might be 1 byte, while bit-fields could be allocated up to the size (in bits) of ints, possibly four bytes in a particular implementation, by choosing larger storage units for larger bit-fields. Is anyone aware of an implementation using bit-field storage units smaller than int? Thad
Technical Details
Message-ID:
<nzRPxQ9ytZZA084yn@csn.net>Path:
arc1-ca.pugleaf.net!teal.csn.net!not-for-mailShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!teal.csn.net!not-for-mail From: thads@csn.net (Thad Smith) Newsgroups: comp.std.c Subject: Bit-field sizes Date: 5 Mar 1996 23:49:35 -0700 Organization: T3 Systems Message-ID: <nzRPxQ9ytZZA084yn@csn.net> Reply-To: ThadSmith@acm.org NNTP-Posting-Host: 199.117.27.22