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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:14:00+00:00 2026-05-16T11:14:00+00:00

Consider this macro: #define MAKE_TEMPLATE(…) template <typename T, __VA_ARGS__ > When used with zero

  • 0

Consider this macro:

#define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ >

When used with zero arguments it produces bad code since the compiler expects an identifier after the comma. Actually, VC’s preprocessor is smart enough to remove the comma, but GCC’s isn’t.
Since macros can’t be overloaded, it seems like it takes a separate macro for this special case to get it right, as in:

#define MAKE_TEMPLATE_Z() template <typename T>

Is there any way to make it work without introducing the second macro?

  • 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-16T11:14:00+00:00Added an answer on May 16, 2026 at 11:14 am

    No, because the macro invocation MAKE_TEMPLATE() does not have zero arguments at all; it has one argument comprising zero tokens.

    Older preprocessors, apparently including GCC at the time this answer was originally written, sometimes interpreted an empty argument list as you’d hope, but the consensus has moved toward a stricter, narrower extension which more closely conforms to the standard.

    To get the answer below to work, define an additional macro parameter before the ellipsis:

       #define MAKE_TEMPLATE(UNUSED, ...) template <typename T, ## __VA_ARGS__ >
    

    and then always put a comma before the first argument when the list is not empty:

       MAKE_TEMPLATE(, foo )
    

    Old answer

    According to http://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html, GCC does support this, just not transparently.

    Syntax is:

       #define MAKE_TEMPLATE(...) template <typename T, ## __VA_ARGS__ >
    

    Anyway, both also support variadic templates in C++0x mode, which is far preferable.

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

Sidebar

Related Questions

Consider a simple macro: #define ECHO(x) x ECHO(foo(1, 2)) This produces the exact output
Consider this (horrible, terrible, no good, very bad) code structure: #define foo(x) // commented
Consider this template function: template<typename ReturnT> ReturnT foo(const std::function<ReturnT ()>& fun) { return fun();
Consider this code: #define N_ 0 #define N_X 1 #define M(a) N_ M(arg)X; //
Consider this unhygienic Scheme macro: (define-macro for (lambda (i i1 i2 . body) (let
Consider this code: enum { ERR_START, ERR_CANNOTOPENFILE, ERR_CANNOTCONNECT, ERR_CANNOTCONNECTWITH, ERR_CANNOTGETHOSTNAME, ERR_CANNOTSEND, }; char* ERR_MESSAGE[]
Consider this (rather pointless) javascript code: function make_closure() { var x = 123, y
Consider this code in a php file on my VPS server: <?php $url =
Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value
Consider the following macro definitions and invocation: #define x x[0] #define y(arg) arg y(x)

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.