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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:51:18+00:00 2026-05-26T01:51:18+00:00

I sometimes deliberately omit macro arguments. For example, for a function-like macro like #define

  • 0

I sometimes deliberately omit macro arguments. For example, for a function-like macro like

#define MY_MACRO(A, B, C)  ...

I might call it as:

MY_MACRO(, bar, baz)

There are still technically 3 arguments; it’s just that the first one is “empty”. This question is not about variadic macros.

When I do this I get warnings from g++ when compiling with -ansi (aka -std=c++98), but not when I use -std=c++0x. Does this mean that empty macro args are legal in the new C++ standard?

That’s the entirety of my question, but anticipating the “why would you want to?” response, here’s an example. I like keeping .h files uncluttered by function bodies, but implementing simple accessors outside of the .h file is tedious. I therefore wrote the following macro:

#define IMPLEMENT_ACCESSORS(TEMPLATE_DECL, RETURN_TYPE, CLASS, FUNCTION, MEMBER) \
  TEMPLATE_DECL                                                         \
  inline RETURN_TYPE* CLASS::Mutable##FUNCTION() {                      \
    return &MEMBER;                                                     \
  }                                                                     \
                                                                        \
  TEMPLATE_DECL                                                         \
  inline const RETURN_TYPE& CLASS::FUNCTION() const {                   \
    return MEMBER;                                                      \
  }

This is how I would use it for a class template that contains an int called int_:

IMPLEMENT_ACCESSORS(template<typename T>, int, MyTemplate<T>, Int, int_)

For a non-template class, I don’t need template<typename T>, so I omit that macro argument:

IMPLEMENT_ACCESORS(, int, MyClass, Int, int_)
  • 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-26T01:51:19+00:00Added an answer on May 26, 2026 at 1:51 am

    If I understand correctly, empty macro argument is allowed since C99 and
    C++0x(11).
    C99 6.10.3/4 says:

    … the number of arguments (including those arguments consisting of
    no preprocessing tokens) shall equal the number of parameters …

    and C++ N3290 16.3/4 has the same statement, while C++03 16.3/10 mentions:

    … any argument consists of no preprocessing tokens, the behavior is
    undefined.

    I think empty argument comes under the representation arguments consisting of
    no preprocessing tokens
    above.
    Also, 6.10.3 in Rationale for International Standard Programming Languages C rev. 5.10
    says:

    A new feature of C99: Function-like macro invocations may also now
    have empty arguments, that is, an argument may consist of no
    preprocessing tokens.

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

Sidebar

Related Questions

Sometimes in Scheme, I have functions that take arguments like this add 3 4
Sometimes you might like a screen snippet in a certain web page, you would
Sometimes, in PL SQL you want to add a parameter to a Package, Function
Sometimes I would like to know how a cool software is made or the
Sometimes I add an attribute to some of my controls. Like: <a href id=myLlink
Sometimes it would be useful to name variables like no programmer should name his
Sometimes google map comes partially with other area getting grayed out. There is one
sometimes Flash Authoring colors my actionscript inappropriately. for example: i have custom variable that
Sometimes when I see a website I like or sites from respected people, I
Sometimes in my code I have a function which can take an argument in

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.