To: Deborah Donovan From: David R Tribble on Thu, Mar 5, 1998 9:24 PM Subject: Comments on ISO/IEC CD 9899 (C9X) Message-Id: <2.2.32.19980306013532.00f1a340@central.beasys.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Thu, 05 Mar 1998 19:35:32 -0600 To: ansi-c9x From: David R Tribble Subject: Comments on ISO/IEC CD 9899 (C9X) Public Comment Number(s) PC-____ to PC-____ ISO/IEC CD 9899 (SC22N2620) Public Comment =========================================== Date: 1998-03-03 Author: David R. Tribble Author Affiliation: Self Postal Address: 6004 Cave River Dr. Plano, TX 75093-6951 USA E-mail Address: dtribble@technologist.com david.tribble@central.beasys.com dtribble@flash.net Telephone Number: +1 972 738 6125, 16:00-00:00 UTC +1 972 964 1729, 01:00-05:00 UTC Fax Number: +1 972 738 6111 Number of individual comments: 1 ------------------------------------------------------------------------ Comment 1. Category: Request for clarification Committee Draft subsection: 6.5.2.1, 6.1.2.8.2, K.2, K.3.9, K.5.8. Title: Bitfield widths Detailed description: Section 6.5.2.1 #8 states that a bitfield can be declared as type 'int', 'signed int', or 'unsigned int'. It further states that "a bitfield is interpreted as a signed or unsigned integer type consisting of the specified number of bits". However, there is no mention of whether or not the number of bits in a bitfield is limited to the number of bits in an '[unsigned] int'. 6.5.2.1#8 implies that a bitfield can be declared with the number of bits in /any/ integer type. This implies that bitfields can be declared to have any number of bits, up to the number of bits in a 'long' or even a 'long long' integer type. Presumably, then, the following declaration is conforming and portable: struct Widdle { unsigned int a: 29; // Exceeds bits in UINT_MAX unsigned int b: 33; // Exceeds bits in ULONG_MAX }; The width of member 'a' exceeds the minimum ISO width of 'unsigned int' of 16 bits, so it must take on the type of 'unsigned long int'. Similarly, the width of member 'b' exceeds the minimum ISO width of 'unsigned long int' of 32 bits, so it must take on the type of 'unsigned long long int'. This seems like a reasonable interpretation. But is it correct? Sections K.2, K.3.9, and K.5.8 state that a compiler may allow types other than 'signed int' and 'unsigned int' for bitfields as an extension. Assuming that the interpretation above is correct, such extensions are superfluous; all bitfield types would be equivalent, and would only be distinguished by their signedness. Suggestion: The maximum allowable size for a bitfield should be mentioned in the standard, perhaps as a footnote to section 6.5.2.1#8: 6.5.2.1 ... [#8] ... A bitfield is interpreted as a signed or unsigned integer type consisting of the specified number of bits *. * This implies that a bitfield may contain any number of bits, up to the number of bits in the widest integer type (umaxint_t). If instead it is deemed a limitation that bitfields cannot have a width that exceeds the number of bits in an '[unsigned] int', then this should be mentioned, perhaps as a footnote. Further, it should be noted in appendix K that exceeding this limit is implementation-defined behavior. ------------------------------------------------------------------------