-4

How memory allocated for"enum" data type, i found that total size of enum data type is 4 bytes(linux) but some people answers is there is no memory allocation, its like 'macros' with a type(int) so please explain how enum all members function stored while accessing and what is data will be there in that 4 bytes.

Thanks

1 Answers1

-1

The memory shall not be allocated for enums. But i could remember that the memory allocation and processing time

(preprocessor time and compilation time) are the main difference between macro and an enum.

For example, while doing debugging(runtime) we will not able to see the value of macro,Since memory is not allocated for macro and we will not able to access the memory location. To know the value of macro, we have to look into the file where it is defined.

But for enums, memory shall be allocated. so that we could able to access the memory and see the value of enum in debugging time(runtime).

So, if memory is not allocated for an enum, then how we could able to know the value in runtime. And from where it access and gives us the value.

msc
  • 33,420
  • 29
  • 119
  • 214
  • 1
    "The memory shall not be allocated for enums" "memory is not allocated for macro" Huh? That's nonsense, you cannot store values in thin air. Everything your program uses must be stored inside the program's memory. Perhaps you meant to say that enumeration _constants_ (and macro constants) are not allocated in the `.data` section, but rather in the `.rodata` or `.text` sections? Unlike enumeration _variables_ that are allocated according to their scope and storage duration. – Lundin Feb 29 '16 at 12:42