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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:06:49+00:00 2026-05-17T21:06:49+00:00

I have some existing code that uses an enum instead of a function pointer

  • 0

I have some existing code that uses an enum instead of a function pointer for callbacks. The callback is called using a table: callback_table[enum].

The enums are named with an enum_ prefix and the corresponding function is named with a func_ prefix.

So, function calls involving callbacks look like this:

foo (param, enum_name);

While browsing code I have to take the name part and prefix func_ instead of just doing a “Jump to definition”.

I would like to have a macro so that my code looks like this:

foo (param, f2e(func_name));

so that I can keep the existing code unchanged and still be able to do a “Jump to definition”.

Is it possible to have such a macro? The simplest solution would be to omit func_ which means that f2e simple attaches the enum_ prefix, but I would prefer a solution where I can still have func_. Is this possible?

  • 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-17T21:06:49+00:00Added an answer on May 17, 2026 at 9:06 pm

    It’s a little round-about, but you could do something like this:

    (let’s assume, for the sake of this example, that you have three possible enum values enum_one, enum_two, and enum_three).

    #define enum_func_one enum_one
    #define enum_func_two enum_two
    #define enum_func_three enum_three
    
    #define f2e(func_name) enum_ ## func_name
    

    the drawback (of course) is that you’ll need a special #define for each possible value of your enum.


    Alternative

    As an alternative, if your only need is to have the function name handy, so you can use your IDE’s “jump to definition” feature… you could do something like this:

    #define f2e(name, func_name)  enum_ ## name
    

    then your call would look like this:

    foo (param, f2e(one, func_one));
    

    a little redundant perhaps, but it would accomplish your goal with minimal intrusion into the rest of your code.

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

Sidebar

Related Questions

I have some existing code that retrieves data from a database using ADO.NET that
I have to analyse some existing Erlang code. Does anybody knows about a tool
Some existing web services I consume have methods that look something like this: List<Employee>
I have an existing database that has some testing data into and I'm interested
I am implementing NHibernate into an existing web application. However, we have some other
I have written a custom ErrorProvider which adds some functionality to the existing ErrorProvider
I have an existing ASP.NET 2.0 website, stored in Team Foundation Server 2005. Some
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some ASP.NET web services which all share a common helper class they

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.