Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 182569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:57:46+00:00 2026-05-11T14:57:46+00:00

I don’t think I fundamentally understand what an enum is, and when to use

  • 0

I don’t think I fundamentally understand what an enum is, and when to use it.

For example:

typedef enum {     kCircle,     kRectangle,     kOblateSpheroid } ShapeType; 

What is really being declared here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:57:47+00:00Added an answer on May 11, 2026 at 2:57 pm

    Three things are being declared here: an anonymous enumerated type is declared, ShapeType is being declared a typedef for that anonymous enumeration, and the three names kCircle, kRectangle, and kOblateSpheroid are being declared as integral constants.

    Let’s break that down. In the simplest case, an enumeration can be declared as

    enum tagname { ... }; 

    This declares an enumeration with the tag tagname. In C and Objective-C (but not C++), any references to this must be preceded with the enum keyword. For example:

    enum tagname x;  // declare x of type 'enum tagname' tagname x;  // ERROR in C/Objective-C, OK in C++ 

    In order to avoid having to use the enum keyword everywhere, a typedef can be created:

    enum tagname { ... }; typedef enum tagname tagname;  // declare 'tagname' as a typedef for 'enum tagname' 

    This can be simplified into one line:

    typedef enum tagname { ... } tagname;  // declare both 'enum tagname' and 'tagname' 

    And finally, if we don’t need to be able to use enum tagname with the enum keyword, we can make the enum anonymous and only declare it with the typedef name:

    typedef enum { ... } tagname; 

    Now, in this case, we’re declaring ShapeType to be a typedef’ed name of an anonymous enumeration. ShapeType is really just an integral type, and should only be used to declare variables which hold one of the values listed in the declaration (that is, one of kCircle, kRectangle, and kOblateSpheroid). You can assign a ShapeType variable another value by casting, though, so you have to be careful when reading enum values.

    Finally, kCircle, kRectangle, and kOblateSpheroid are declared as integral constants in the global namespace. Since no specific values were specified, they get assigned to consecutive integers starting with 0, so kCircle is 0, kRectangle is 1, and kOblateSpheroid is 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
Don't really know how to formulate the title, but it should be pretty obvious
I don't understand the meaning of $:<< . in Ruby. I upgraded Ruby to
I don't really know too much about core JavaScript, just a dot of jQuery.
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't quite understand why this copy constructor is not invoked when I build with
Don't think my virtualhost is working correctly. This is what I have inside of
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
I don't like Jackson. I want to use ajax but with Google Gson. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.