Topic : enum items size

Forum : 8051

Original Post
Post Information Post
February 5, 2007 - 12:45pm
Guest

Hello,
I don't understand the reason why this piece of code allocate 2 byte of code space for each enum's item.

#pragma ET(char)

enum {ONE=1,TWO=2,THREE=3};

void main()
{
// dummy
}

this is the compiler's output.

NAME CLASS MSPACE TYPE OFFSET SIZE
==== ===== ====== ==== ====== ====

ONE. . . . . . . . . . . . . . . . . . E_CONST ----- INT ----- 2
TWO. . . . . . . . . . . . . . . . . . E_CONST ----- INT ----- 2
THREE. . . . . . . . . . . . . . . . . E_CONST ----- INT ----- 2
main . . . . . . . . . . . . . . . . . PUBLIC CODE PROC ----- -----
RC51 COMPILER V03.03.39, ADAPTER 02/05/07 12:19:53 PAGE 1

Replies
Post Information Post
+1
0
-1
February 5, 2007 - 2:14pm
Guest

No, this declaration does not allocate anything (only variables declaration will consume memory).
Moreover, the official type size is int, but any variable declared of this type will be considered as a single byte (because of the pragma). You can easily check it by looking at the total code of your project (that does not change if you comment out this line).
On the other hand, you are right that we could remove these declarations from the table of the listing.
Francis