This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug exp/8156] GNU/Linux, gcc, C, enum


------- Additional Comments From tromey at redhat dot com  2009-01-03 02:35 -------
I believe that this is actually the correct behavior.

In the source, the expression that defines the value of an enumeration
constant must be representable as an int.

However, the type of the enumeration itself is implementation-defined,
and must only be compatible with char, a signed integer type, or an
unsigned integer type (C99 6.7.2.2).

GCC (info "(gcc)Structures, unions, enumerations, and bit-fields")
defines the type as:

     Normally, the type is `unsigned int' if there are no negative
     values in the enumeration, otherwise `int'.  If `-fshort-enums' is
     specified, then if there are negative values it is the first of
     `signed char', `short' and `int' that can represent all the
     values, otherwise it is the first of `unsigned char', `unsigned
     short' and `unsigned int' that can represent all the values.

     On some targets, `-fshort-enums' is the default; this is
     determined by the ABI.

In the example program, the enum has no negative values, so GCC chooses
unsigned int.  When I modify the program to read "firstEnumMember =-1",
gdb correspondingly changes:

(gdb) ptype firstEnumMember+0
type = int

I did not test the -fshort-enums case.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |INVALID


http://sourceware.org/bugzilla/show_bug.cgi?id=8156

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]