How does enums types initializations in recursive functions work?

If I have an enum type declaration in a recursive function, will it be ‘created’ multiple times?

Does it work like ‘#define’ in the sense that it just tells the pre-processor to ‘swap’ values (but with scope in mind)?
What would happen here, per example:

void recuFun() 
{
  enum someEnum {UP, DOWN, LEFT, RIGHT}; // Initialized multiple times?
  /* ... */
  recuFun();
}

I know that enum types aren’t objects, and therefore won’t be allocated to memory. but I’m not sure what’s happening here, and as far as I know, it isn’t a pre-processor ‘swap’ thing. it feels as if I’m wasting memory, or something like it.

>Solution :

An enum doesn’t really exist at the assembly/machine code level; it’s all integral values there.

Declaring an enum or typedef enum in a recursive function will not use any more resources than declaring it in any other scope.

Leave a Reply