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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:49:37+00:00 2026-05-27T02:49:37+00:00

I am trying to create a macro (C/C++) to dynamically create a function. Basically

  • 0

I am trying to create a macro (C/C++) to dynamically create a function. Basically I have a function whose name varies in the “MyClassA” part. Also the arguements should be passed through the macro definition. Then there is a variable method call within the function, for instance “methodForClassA”, again with a variable set of arguements.

void Java_somepackage_MyClassA_fixMethod(int arg1, int arg2) {
Toolbox.methodForClassA(arg1, arg2);
}

There are more than 40 functions with this pattern. Of course I can create them manually or with a script. But is it also possible to do this with a macro? For instance something like this (which does not work):

# define MACRO_TEST(classname, methodname, args, argsMethod) void Java_somepackage_##classname_fixMethod(##args) {\
    Toolbox.##methodname(##argsMethod);\
} 
MACRO_TEST(MyClassA, methodForClassA, args1, args2)

After some experimentation and reading of docs, I could only find out how to create “dynamic” function names with patterns where a “(” follows the dynamic part:

#define FUNCTION(name, x) int func_##name() { return x;}
FUNCTION(test, 2);

Regards,

  • 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-27T02:49:37+00:00Added an answer on May 27, 2026 at 2:49 am

    I think you may be misunderstanding the purpose of the ## symbol pasting operator. You don’t need to put ## in front of every use of a macro argument, only when you want to paste it together with some other text to create one symbol in the output. So, you will probably need it, but not everywhere.

    So this is closer:

    # define MACRO_TEST(classname, methodname, args, argsMethod) \
    void Java_somepackage_##classname##_fixMethod(args) {\
        Toolbox.methodname(argsMethod);\
    } 
    MACRO_TEST(MyClassA, methodForClassA, args1, args2)
    

    However, this still doesn’t work. Your args parameter I guess contains a variable number of parameters. In newer versions of C, there’s something called “variadic macro parameters” but I’ve never used them. Or, you could surround your parameters with parentheses in the macro call, like this:

    # define MACRO_TEST(classname, methodname, args, argsMethod) \
    void Java_somepackage_##classname##_fixMethod args  {\
        Toolbox.methodname argsMethod;\
    } 
    MACRO_TEST(MyClassA, methodForClassA, (int arg1, int arg2), (arg1, arg2))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a macro that brings in the name of the
I'm trying to create a Macro function for defining function pointers , functions etc.
I'm basically trying to figure out how to create a macro in Outlook that
Trying to create a macro which can be used for print debug messages when
I'm trying to create a macro for Keyboard Maestro for OS X doing the
I am trying to create a Macro that either runs on close or on
I'm trying to create a macro that selects most of the sheets in the
I'm trying to create a fairly simple macro in Word 2010 using Visual Basic.
I am trying to create a Word document with a very simple word macro.
I'm trying (as a self-learning exercise) to create a Clojure macro that will generate

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.