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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:47:45+00:00 2026-06-15T21:47:45+00:00

This question is a follow-on from https://stackoverflow.com/a/5365786/383306 . #define _DEFINE_REF_INTERNAL2(id, …) #define _DEFINE_REF_INTERNAL1(id) #define

  • 0

This question is a follow-on from https://stackoverflow.com/a/5365786/383306.

#define _DEFINE_REF_INTERNAL2(id, ...)

#define _DEFINE_REF_INTERNAL1(id)

#define _VA_NARGS_2_IMPL(_1, _2, N, ...) N
#define _VA_NARGS_2(...) _VA_NARGS_2_IMPL(__VA_ARGS__, 2, 1)
#define _DEFINE_REF_IMPL2(count, ...) _DEFINE_REF_INTERNAL ## count (__VA_ARGS__)
#define _DEFINE_REF_IMPL(count, ...) _DEFINE_REF_IMPL2(count, __VA_ARGS__)
#define DEFINE_REF(...) _DEFINE_REF_IMPL(_VA_NARGS_2(__VA_ARGS__), __VA_ARGS__)

DEFINE_REF(MyClass, typename... Args, Args...); 
// error: ‘_DEFINE_REF_INTERNALArgs’ does not name a type
DEFINE_REF(MyClass, typename T, T); // this is OK

How do I make the macro trick work when passing ellipsis as part of an argument?

  • 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-15T21:47:47+00:00Added an answer on June 15, 2026 at 9:47 pm

    The problem isn’t with the ellipsis. The problem is that you are passing three arguments in __VA_ARGS__ to DEFINE_REF, but _VA_NARGS_2 only handles up to two arguments.

    Once you fix that, the program (I believe) exhibits the desired behavior. gcc 4.7.2 and Clang 3.2 both transform this:

    #define DEFINE_REF_INTERNAL3(arg0, arg1, arg2) [arg0] [arg1] [arg2]
    
    #define VA_NARGS_(_1, _2, _3, N, ...) N
    #define VA_NARGS(...) VA_NARGS_(__VA_ARGS__, 3, 2, 1)
    
    #define DEFINE_REF_IMPL_(count, ...) DEFINE_REF_INTERNAL ## count(__VA_ARGS__)
    #define DEFINE_REF_IMPL(count, ...) DEFINE_REF_IMPL_(count, __VA_ARGS__)
    
    #define DEFINE_REF(...) DEFINE_REF_IMPL(VA_NARGS(__VA_ARGS__), __VA_ARGS__)
    
    DEFINE_REF(MyClass, typename... Args, Args...); 
    DEFINE_REF(MyClass, typename T,       T      );
    

    into this:

    [MyClass] [typename... Args] [Args...];
    [MyClass] [typename T] [T];
    

    (Also note that names beginning with an underscore followed by a capital letter are reserved for the implementation. You may not use such names for your own macros.)


    If you are targeting Visual C++, you will need a barrel of indirection to make this work, as it does not correctly replace macros before rescanning in all cases. The following will work with Visual C++ (This solution is also conforming and works with gcc and Clang as well):

    #define DEFINE_REF_INTERNAL3(id, arg0, arg1) id [arg0] [arg1]
    
    #define CONCATENATE_(x, y) x ## y
    #define CONCATENATE(x, y) CONCATENATE_(x, y)
    
    #define VA_NARGS1(_1, _2, _3, N, ...) N
    #define VA_NARGS0(x) VA_NARGS1 x
    #define VA_NARGS(...) VA_NARGS0((__VA_ARGS__, 3, 2, 1))
    
    #define DEFINE_REF_IMPL1(macro, pargs) macro pargs
    #define DEFINE_REF_IMPL0(count, ...) \
        DEFINE_REF_IMPL1(CONCATENATE(DEFINE_REF_INTERNAL, count), (__VA_ARGS__))
    #define DEFINE_REF_IMPL(count, ...) DEFINE_REF_IMPL0(count, __VA_ARGS__)
    
    #define DEFINE_REF(...) DEFINE_REF_IMPL(VA_NARGS(__VA_ARGS__), __VA_ARGS__)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow on from another question ( https://stackoverflow.com/questions/10712659/c-class-design-for-monte-carlol-simulation ) I am planning
A follow on from this questions: http://stackoverflow.com/questions/3032598/rails-created-at-on-display-if-today Is it possible to output the word
This is a follow up on a related topic found here https://stackoverflow.com/questions/1987485/conditionally-assign-c-var-as-elegant-as-it-get s if
This is a follow-up to what I was trying to accomplish here https://stackoverflow.com/questions/7313922/uploading-files-ussing-myfaces-tomahawk-jsf-2-0 I've
This question is a follow on from this one ... I am binding to
This is a follow-on from this question, in which I was trying to suppress
This is a follow on from my previous question although this is about something
This is a follow up question from Calling constructor in return statement . This
This is a follow-on question from the one I asked here . Can constraints
This is a follow up from my previous question I have this code basically

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.