Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/29/08 15:24
Read: times


 
#150062 - Know Thy Stuff - enum
Responding to: ???'s previous message
Neil Kurzman said:
I think enum behaves as a signed int. But the compiler may use 8 bits if the enum sequence will fit

Brett Wallace said:
I think the only reqiurement on the type of an enum is it must fit the value. I think most compilers will use the smallest size that works for the value entered...

OK, here's chapter & verse:

ISO/IEC 9899:1990, section 6.5.2.2, said:
Constraints
The expression that defines the value of an enumeration constant shall be an integral constant expression that has a value representable as int.

Semantics
The identifiers in an enumerator list are declared as constants that have type int


ISO/IEC 9899:1990, section 6.1.3.3, said:
Semantics
An identifier declared as an enumeration constant has type int


ISO/IEC 9899:1990, section 6.1.2.3, said:
Types
There are four signed integer types, designated as signed char, short int, int, and long int.



Thus enum constants are ints, and ints are implicitly signed.

Having said that, it is true that many compilers do have options to control the type(s) used for enums...


List of 28 messages in thread
TopicAuthorDate
The art of typecasting            01/01/70 00:00      
   I'd like to disagree            01/01/70 00:00      
   two comments            01/01/70 00:00      
      Two comments on comments            01/01/70 00:00      
   The Art of correct Constants            01/01/70 00:00      
      int - number of bits unknown            01/01/70 00:00      
         Corrected Art of correct Constants            01/01/70 00:00      
         More assumptions            01/01/70 00:00      
         stdint.h            01/01/70 00:00      
            Or, in the absence of stdint.h...            01/01/70 00:00      
      Const vs #define            01/01/70 00:00      
         Opps!            01/01/70 00:00      
            which may be a reason to prefer #define over const            01/01/70 00:00      
               enum            01/01/70 00:00      
                  Varies            01/01/70 00:00      
                     Know Thy Stuff - enum            01/01/70 00:00      
                        You are right            01/01/70 00:00      
   Know Thy Stuff            01/01/70 00:00      
      And...            01/01/70 00:00      
         I'll pass(cal) on that one :)            01/01/70 00:00      
   Everything in C defaults to int, which is signed            01/01/70 00:00      
   Never overlook lint            01/01/70 00:00      
      before Steve says it...            01/01/70 00:00      
         Pascal            01/01/70 00:00      
            strong typing            01/01/70 00:00      
               why Ada never took off            01/01/70 00:00      
                  Wirth-less            01/01/70 00:00      
               Why ?            01/01/70 00:00      

Back to Subject List