[ofa-general] [PATCH ibverbs] Do not use enum object types for bitfields

Bart Van Assche bart.vanassche at gmail.com
Wed Jul 29 22:54:19 PDT 2009


On Wed, Jul 29, 2009 at 11:29 PM, Roland Dreier<rdreier at cisco.com> wrote:
> By the way, I just did some research and
> <http://wiki.debian.org/ArmEabiPort#Enumsizes>
> indicates that on current arm ABI, enums are the same size as int.
>
> and
> <http://developers.sun.com/solaris/articles/about_amd64_abi.html>
> indicates that sparc32 and sparc64 both use int for enum.
>
> and I found a mips cross compiler and tested there, and int works there
> as well.
>
> So I'm pretty comfortable with this patch (once the man pages and other
> doc get fixed to match the changes).

If I'm not mistaken, the ANSI/ISO C standard requires that enums have the
same size as an int. Two quotes from JTC1/SC22/WG14 working group, *Draft
standard for the ANSI C programming
language<http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n843.pdf>
*, August 3, 1998:

*6.2.5 Types [ ... ] 16. An enumeration comprises a set of named integer
constant values. Each distinct enumeration constitutes a different
enumerated type.
*
*6.7.2.2 Enumeration specifiers [ ... ] 2 The expression that defines the
value of an enumeration constant shall be an integer constant expression
that has a value representable as an int.*

This does not hold for C++ however. A C++ compiler may use an integral type
larger or smaller than an int to represent an enumeration type. A quote from
Bjarne Stroustrup, *The C++ Programming Language*, Special Edition, Addison
Wesley, 2000:

*The sizeof an enumeration is the sizeof some integral type that can hold
its range and not larger size of size of than sizeof(int), unless an
enumerator cannot be represented as an int or as an unsigned int.
*
Bart.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20090730/4096a546/attachment.html>


More information about the general mailing list