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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:24:25+00:00 2026-06-08T20:24:25+00:00

I have two macros FOO2 and FOO3 : #define FOO2(x,y) … #define FOO3(x,y,z) …

  • 0

I have two macros FOO2 and FOO3:

#define FOO2(x,y) ...
#define FOO3(x,y,z) ...

I want to define a new macro FOO as follows:

#define FOO(x,y) FOO2(x,y)
#define FOO(x,y,z) FOO3(x,y,z)

But this doesn’t work because macros do not overload on number of arguments.

Without modifying FOO2 and FOO3, is there some way to define a macro FOO (using __VA_ARGS__ or otherwise) to get the same effect of dispatching FOO(x,y) to FOO2, and FOO(x,y,z) to FOO3?

  • 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-08T20:24:27+00:00Added an answer on June 8, 2026 at 8:24 pm

    Simple as:

    #define GET_MACRO(_1,_2,_3,NAME,...) NAME
    #define FOO(...) GET_MACRO(__VA_ARGS__, FOO3, FOO2)(__VA_ARGS__)
    

    So if you have these macros, they expand as described:

    FOO(World, !)         // expands to FOO2(World, !)
    FOO(foo,bar,baz)      // expands to FOO3(foo,bar,baz)
    

    If you want a fourth one:

    #define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
    #define FOO(...) GET_MACRO(__VA_ARGS__, FOO4, FOO3, FOO2)(__VA_ARGS__)
    
    FOO(a,b,c,d)          // expands to FOO4(a,b,c,d)
    

    Naturally, if you define FOO2, FOO3 and FOO4, the output will be replaced by those of the defined macros.

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

Sidebar

Related Questions

I have about two macros (and climbing) in my codebase that look like this:
I have two macros that declares class properties: DECLARE_QUERY_PARAM_LONG(name) DECLARE_QUERY_PARAM_STRING(name) I want to count
I have a problem to create a preprocessor macro function, that concatenates two Strings
I have two update panels on a page. And I want to update both
working on an ANT build file, where I have two macros defined and need
I have two 2-D arrays close and open I have defined 2 macros min(a,b)
This may seem silly but I seem to have forgotten the order of replacement
I'm currently implementing a profiling system into an application. I have a two macro
I have two macros. The first one takes a symbol as the only parameter
I have developed two MS Word macros and assigned each an icon. I have

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.