Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading