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 478033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:39:03+00:00 2026-05-13T00:39:03+00:00

I was getting a little confused with typedef/enum until I realised that I did

  • 0

I was getting a little confused with typedef/enum until I realised that I did not need to name the emun. Are there any differences / benefits between these two when used with typedef, the 2nd one to me seems a lot easier to understand.

First Example:

typedef enum enumMenuItems {
    none,
    add,
    save,
    load,
    list,
    remove
} menuItems;

menuItems optionSelect = none;

Second Example:

typedef enum {
    Earth = 1, 
    Mars,
    Saturn,
    Neptune,
    Jupiter
} planets;

planets closest = Mars;

.

EDIT:

typedef enum enumMenuItems {
    none,
    add,
    save,
    load,
    list,
    remove
} menuItems;

So the above essentially defines two types, one an enum called enumMenuItems and the second a typedef of enumMenuItems called menuItems.

menuItems optionSelect = save;
enum enumMenuItems optionSelect = save;

The above two declarations are essentially the same, one using the typedef and the other using the enum. So if your using a typedef you can leave your enum unnamed as the type can be accessed via the typedef menuItem.

gary

  • 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. Editorial Team
    Editorial Team
    2026-05-13T00:39:04+00:00Added an answer on May 13, 2026 at 12:39 am

    The first case allows you to refer to the type as enum enumMenuItems. For example:

    enum enumMenuTimes optionSelect = none;
    

    It might be clearer if you break it down into two parts:

    enum _planets { 
        Earth = 1, 
        Mars, 
        Saturn,
        Neptune,
        Jupiter
    };
    typedef enum _planets planets;
    
    enum _planets planet1 = Earth;
    planets       planet2 = Mars;
    

    If that simplifies the concept for you. Your second notation there is just shorthand; it creates an anonymous enumeration and then uses typedef to give it a name. You could even, for example, do:

    enum {
        Value0,
        Value1,
        Value2
    };
    

    But you’d not be able to use the enumeration as a fake type name, like you’re trying to do. You can still access the enumerated values, though.

    A more in depth description is available at the comp.lang.c FAQ.

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

Sidebar

Related Questions

I am getting a little confused and need some help please. Take these two
I'm getting a little confused how to set up a class that's two steps
Getting a little confused here, not sure if its the monday morning blues! Its
I am doing one project on Struts 2 that I am getting knowledge little
I need a little help getting a tar file to download from a website.
I'm getting a little confused about bubbling. <html> <body> <div onclick=window.location='http://www.yahoo.com';> <span> <h3 onclick=window.location='http://www.google.com';>
Im using strtok and getting a little confused. I have an array holding a
I'm pretty new to Python and am getting a little confused as to what
I'm getting into Google Web Toolkit, and am a little confused about the Entry
OK, I am getting myself a little confused here. I have a WCF service

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.