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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:50:23+00:00 2026-06-15T06:50:23+00:00

#define PP_ARG0_(arg0, …) arg0 #define PP_REST_(arg0, …) __VA_ARGS__ #define PP_ARG0(args) PP_ARG0_ args #define PP_REST(args)

  • 0
#define PP_ARG0_(arg0, ...) arg0
#define PP_REST_(arg0, ...) __VA_ARGS__
#define PP_ARG0(args) PP_ARG0_ args
#define PP_REST(args) PP_REST_ args

#define FUNCTION(name) void name();
#define FUNCTION_TABLE(...)                   \
    FUNCTION(PP_ARG0((__VA_ARGS__)))          \
    FUNCTION_TABLE(PP_REST((__VA_ARGS__)))    \

test code:

FUNCTION_TABLE(f1, f2,f3,testA,testB,testC);

Obviously, because of recursive expansion it will only declare void f1(); and the rest won’t be expanded:

void f1(); FUNCTION_TABLE(f2,f3,testA,testB,testC);

What kind of trick can I use to achieve recursive expansion in this case? The problem is that I need to support MANY arguments (up 100) and I absolutely cannot use boost.

  • 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-15T06:50:26+00:00Added an answer on June 15, 2026 at 6:50 am

    Here’s the answer in case somebody wants to do the same.

    #define _PP_0(_1, ...) _1            // (a,b,c,d) => a
    #define _PP_X(_1, ...) (__VA_ARGS__) // (a,b,c,d) => (b,c,d)
    
    //for each a in __VA_ARGS__ do f(a,x) 
    //where x is some parameter passed to PP_TRANSFORM
    #define PP_TRANSFORM(f,x,...) \
        PP_JOIN(PP_TRANSFORM_,PP_NARG(__VA_ARGS__))(f,x,(__VA_ARGS__))
    
    #define PP_TRANSFORM_0(...)
    #define PP_TRANSFORM_1( f,x,a) f(_PP_0 a,x) PP_TRANSFORM_0( f,x,_PP_X a)
    #define PP_TRANSFORM_2( f,x,a) f(_PP_0 a,x) PP_TRANSFORM_1( f,x,_PP_X a)
    ...
    #define PP_TRANSFORM_51(f,x,a) f(_PP_0 a,x) PP_TRANSFORM_50( f,x,_PP_X a)
    ...
    #define PP_TRANSFORM_99(f,x,a) f(_PP_0 a,x) PP_TRANSFORM_98(f,x,_PP_X a)
    #define PP_TRANSFORM_100(f,x,a)f(_PP_0 a,x) PP_TRANSFORM_99(f,x,_PP_X a)
    

    where PP_NARG is the macro that counts number of arguments and PP_JOIN is the macro that joins tokens (that is PP_JOIN(a,b) => ab). You’ll also need to patch that PP_NARG if you want to be able to process more than 64 arguments.

    Now, back to the original question. Solution using the PP_TRANSFORM is:

    #define FUNCTION(name, dummy) void name();
    #define FUNCTION_TABLE(...) PP_TRANSFORM(FUNCTION,dummy,__VA_ARGS__)
    

    if you want to generate c++ implementation functions then you can use that opaque x parameter of PP_TRANSFORM:

    #define FUNCTION_CPP(name, class) void class::name(){}
    #define FUNCTION_TABLE_CPP(...) PP_TRANSFORM(FUNCTION_CPP,MyClass,__VA_ARGS__)
    

    All this works equally well with GCC and MSVC preprocessors; PP_TRANSFORM_NN doesn’t use __VA_ARGS__ to avoid separate implementations of 100 defines for GCC and MSVC

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

Sidebar

Related Questions

Ext.define('DigitalPaper.controller.Documents', { extend: 'Ext.app.Controller', views: ['Documents'], stores: ['Documents'], models: ['Documents'], init: function() { console.log('[OK]
code: #define f(a,b) a##b #define g(a) #a #define h(a) g(a) main() { printf(%s\n,h(f(1,2))); //[case
Based on pp. 8 Free Functions template<typename T> void swap(scoped_ptr<T>& a,scoped_ptr<T>& b) This function
Consider the following sample code. #define T(q) L##q #define A(p) T(x T(#p)) wchar_t w[]
This is my code : <?php require_once 'classes/dbconnect.php'; $connector = new dbconnect(); pp(); function
I'm trying to use Function to define a recursive definition using a measure, and
I use macros to code unrolled loops like this: (silly example) #define foreach_small_prime(p, instr)
please consider these files: p.h: #ifndef _p_h_ #define _p_h_ class p{ public: static void
The following code compiles fine. #define CMD_MACRO(pp, cmd) \ { \ if (pp)\ {
#define BUF_SIZE 10 char *html = foo:baa\r\nxxx:yyyy:\r\nLocation:........................................\r\Connection:close\r\n\r\n; char *p = (char*)html, *buf, *pbuf, *tbuf;

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.