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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:17:56+00:00 2026-06-18T07:17:56+00:00

I try to use code which is generating functions via a macro, which looks

  • 0

I try to use code which is generating functions via a macro, which looks like this:

File A (Provided file I can’t change anything here):

#define FUNCTION_GENERATOR(NUM) \
void MyGeneratedFunctionNo##NUM##(void) \
{ \
     another_function_call(NUM); \
} \

FUNCTION_GENERATOR(1)
FUNCTION_GENERATOR(2)
FUNCTION_GENERATOR(3)

File B (My file where I wanna use function pointers to the generated functions from File A):

typedef void (*function_ptr) (void);
function_ptr func_array[3];
func_array[0] = MyGeneratedFunctionNo1;
func_array[1] = MyGeneratedFunctionNo2;
func_array[2] = MyGeneratedFunctionNo3;
...

Naturally the compiler complains that MyGeneratedFunctionNo1, MyGeneratedFunctionNo2, MyGeneratedFunctionNo3 are not defined.

Is there any way to use function pointers with this
generated functions?

  • 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-06-18T07:17:57+00:00Added an answer on June 18, 2026 at 7:17 am

    The problem has nothing to do with function pointers per se. You will not be able to access these functions from other translation units in any way, pointers or not, because they are not declared in other translation units.

    The typical macro based technique implies providing and using two macros: one for generating declarations and one for generating definitions

    #define FUNCTION_GENERATOR_DECL(NUM) \
    void MyGeneratedFunctionNo##NUM(void);
    
    #define FUNCTION_GENERATOR_DEF(NUM) \
    void MyGeneratedFunctionNo##NUM(void) \
    { \
         another_function_call(NUM); \
    }
    

    After that you use the “definition” macro instantiations in some implementation file (as you already do)

    FUNCTION_GENERATOR_DEF(1)
    FUNCTION_GENERATOR_DEF(2)
    FUNCTION_GENERATOR_DEF(3)
    

    and you typically place the “declarator” macro instantiations into some header file.

    FUNCTION_GENERATOR_DECL(1)
    FUNCTION_GENERATOR_DECL(2)
    FUNCTION_GENERATOR_DECL(3)
    

    P.S. Also, note an important subtle point mentioned by @James Kanze in the comments (and which I missed initailly). The ## operator shall not be used to form invalid preprocessing tokens. In the preprocessor grammar ( is a separate independent preprocessing token (punctuator), while the function name is also a separate independent preprocessing token (identifier). If you attempt to forcefully concatenate the function name to the ( by using the ## operator, you’ll end up with an invalid preprocessing token and undefined behavior.

    Don’t concatenate the ( to the function name. Remove the second ## from your macro definition. It will work as intended without it.

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

Sidebar

Related Questions

I try to update my profile image and use this code: $connection->post('account/update_profile_image', array('image' =>
Here a simple question : What do you think of code which use try
I'm trying to use the code which available on: How can I play sound
i'm trying to use this code which i called from a button but it
In Flash Builder (flex 4) I try to use next code to set selected
I try to use the following code: ArrayList<String> Map<String, String> Eclipse complains about both
I try use a integer array in java with the code below: public static
i use below code - Just try again. - to prevent deadlock. it seems
I use the following code try to create an array of string vectors, I
I try to use a variable in my kshell script but can't get a

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.