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

  • Home
  • SEARCH
  • 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 42957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:25:10+00:00 2026-05-10T15:25:10+00:00

What is the best approach to define additional data for typedef enums in C?

  • 0

What is the best approach to define additional data for typedef enums in C?

Example:

typedef enum {   kVizsla = 0,   kTerrier = 3,   kYellowLab = 10 } DogType; 

Now I would like to define names for each, for example kVizsla should be ‘vizsla’. I currently use a function that returns a string using a large switch block.

  • 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-10T15:25:10+00:00Added an answer on May 10, 2026 at 3:25 pm

    @dmckee: I think the suggested solution is good, but for simple data (e.g. if only the name is needed) it could be augmented with auto-generated code. While there are lots of ways to auto-generate code, for something as simple as this I believe you could write a simple XSLT that takes in an XML representation of the enum and outputs the code file.

    The XML would be of the form:

    <EnumsDefinition>     <Enum name='DogType'>         <Value name='Vizsla' value='0' />         <Value name='Terrier' value='3' />         <Value name='YellowLab' value='10' />     </Enum> </EnumsDefinition> 

    and the resulting code would be something similar to what dmckee suggested in his solution.

    For information of how to write such an XSLT try here or just search it up in google and find a tutorial that fits. Writing XSLT is not much fun IMO, but it’s not that bad either, at least for relatively simple tasks such as these.

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

Sidebar

Ask A Question

Stats

  • Questions 59k
  • Answers 59k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Passes it by reference. Huh? Passing by reference means that… May 11, 2026 at 8:58 am
  • added an answer You must wait on the bufferLock, not m_mutex: while (!m_bStop)… May 11, 2026 at 8:58 am
  • added an answer Yes and no. You cannot directly expose the generic class… May 11, 2026 at 8:58 am

Related Questions

What is the best approach to define additional data for typedef enums in C?
What is the best approach to synchronizing a DataSet with data in a database?
What is the best approach to calculating the largest prime factor of a number?
What is the best approach to releasing a new version of a hosted web
What is the best approach to implementing authorisation/authentication for a Windows Forms app talking
What is the best approach to encapsulate objects and manage their lifetime? Example: I
Does anybody know what is the best approach to accessing a sql view through
In ASP.NET (not MVC), what is the best approach to programmatically setting styles on
What is the best way to approach removing items from a collection in C#,
and to spice things a bit , what is the best approach for globalization

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.