Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define an array with enum variable as array size

Tags:

arrays

c

enums

What does it mean to define an array with enum variable as array size?

For example I have the following code:

typedef enum
{
  D_ROM_RDE_GROUP_0 = 0x0,
  D_ROM_RDE_GROUP_1,   

  D_ROM_RDE_MAX_GROUPS

}E_ROM_RDE_GROUPS;

U_08 pPlaneCopy[D_ROM_RDE_MAX_GROUPS];

I don't understand it...

Thanks for the help.

like image 447
Assaf Malki Avatar asked Nov 10 '13 16:11

Assaf Malki


1 Answers

The first thing to remember is that enumeration values are compile-time constant. The other thing is that enumeration values (unless initialized to a specific value) increases. So in your case D_ROM_RDE_GROUP_0 is equal to 0, D_ROM_RDE_GROUP_1 is equal to 1 and D_ROM_RDE_MAX_GROUPS is equal to 2.

This means that when you declare the array, it's basically the same thing as

U_08 pPlaneCopy[2];
like image 66
Some programmer dude Avatar answered Oct 06 '22 00:10

Some programmer dude