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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:07:09+00:00 2026-06-02T23:07:09+00:00

In an example project, I defined the macro #define FOO(x, y) x + y

  • 0

In an example project, I defined the macro

#define FOO(x, y) x + y   .

This works perfectly well. For example, FOO(42, 1337) is evaluated to 1379.

However, I now want to use another #define:

#define SAMPLE 42, 1337

When I now call FOO(SAMPLE), this won’t work. The compiler tells me that FOO takes two arguments, but is only called with one argument.

I guess that the reason for this is that, although, the arguments of a macro are evaluated in advance of the function itself, that the preprocessor does not parse the whole instruction again after this evaluation. This is a similar to the fact that it is not possible to output additional preprocessor directives from a macro.

Is there any possibility to get the desired functionality?

Replacing the FOO macro with a C function is not a possibility. The original macro is located in third party code I cannot change, and it outputs a comma-separated list of values to be directly used in array initializers. Therefore, a C function cannot replicate the same behaviour.

If it is not possible to accomplish this task by using simple means: How would you store the (x, y) pairs in a maintainable form? In my case, there are 8 arguments. Therefore, storing the individual parts in separate #define-s is also not easy maintainable.

  • 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-02T23:07:11+00:00Added an answer on June 2, 2026 at 11:07 pm

    You’re running into a problem where the preprocessor is not matching and expanding macros in the order you want. Now you can generally get it to do what you want by inserting some extra macros to force it to get the order right, but in order to that you need to understand what the normal order is.

    • when the compiler sees the name of a macro with arguments followed by a ( it first scans in that argument list, breaking it into arguments WITHOUT recognizing or expanding any macros in the arguments.

    • after parsing and separating the arguments, it then rescans each argument for macros, and expands any it finds withing the argument UNLESS the argument is used with # or ## in the macro body

    • it then replaces each instance of the argument in the body with the (now possibly expanded) argument

    • finally, it rescans the body for any OTHER macros that may exist with the body for expansion. In this one scan, the original macro WILL NOT be recognized and reexpanded, so you can’t have recursive macro expansions

    So you can get the effect you want by careful use of an EXPAND macro that takes a single argument and expands it, allowing you to force extra expansions at the right point in the process:

    #define EXPAND(X)   X
    #define FOO(x,y)    x + y
    #define SAMPLE      42, 1337
    
    EXPAND(FOO EXPAND((SAMPLE)))
    

    In this case you first explicitly expand macros in the argument list, and then manually expand the resulting macro call afterwards.

    Update by question poster

    #define INVOKE(macro, ...) macro(__VA_ARGS__)
    
    INVOKE(FOO, SAMPLE)
    

    provides an extended solution that works without cluttering the code with EXPANDs.

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

Sidebar

Related Questions

http://plugins.jquery.com/project/conmenu its a plugin for right click menu..... however it has no example usages
I am wondering if macro definitions can contain space. Let's take for example this
i'm download DrillDownApp example project from iPhoneSDKArticles i have a problem when i'm try
I'm looking for a good example project/tutorial that show the Kiwi testing framework in
1.I have successfully run the ScanTest example project in my xcode4.2.1 2.And then I
I need to have : http://www.example.com/v1/my-project/ redirected to http://example.com/my-project/ so : (1) remove the
In my project i'm using enums example: public enum NcStepType { Start = 1,
A specific example: becoming familiar with django's project source code (core, contrib, utils, etc.).
I have a simple java project (adapted from the example here ), which is
I am building a project in Visual C++ 2008, which is an example MFC-based

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.