Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
10.3 and storing enums in integers
#2
This is alright because K1 is declared as an anonymous enumeration type enum { K1=1, K2=128 };

Section 8.10.2 lists the possible essential type categories. This includes the following note.
Quote: Another exception is the use of anonymous enumerations as defined in Appendix D. Anonymous enumerations are a way of defining a set of related constant integers and are consider to have an essentially signed type.
Appendix D.5 gives the definition of anonymous enum type as
Quote:An anonymous enum type is an enumeration which does not have a tag and which is not used in the definition of any object, function or type.
Appendix D.6 gives the type of anonymous enum constants as
Quote:The following anonymous enum type defines a set of constants. The essential type of each constant is the STLR. Therefore on a machine with 8-bit char and 16-bit short types, A and B have an essential type of signed char but C has an essential type of signed short.
enum { A = 8, B = 64, C = 128 };
The essential type of the K1 enumeration constant is therefore determined as the STLR of the literal "1", which means that the essential type of K1 is signed char.
Posted by and on behalf of the MISRA C Working Group


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)