Questions tagged [variadic-macros]

Variadic macros are a feature of the C-preprocessor that permit a variable number of arguments to a macro. They were added in the 1999 revision of the C standard.

Variadic macros are a feature of the C-preprocessor that permit a variable number of arguments to a macro. They were added in the 1999 revision of the C standard.

More details can be obtained from:

295 questions
1
vote
1 answer

Concat string with __VA_ARGS__

I've the following macro: #define MY_FCT1( id, ... ) \ FCT( id,__VA_ARGS__ ); \ and I want to create a new one to do something like this: #define MY_FCT2( id, ... ) \ MY_FCT1( id, (" %s : ",Name())"…
1
vote
2 answers

Variadic Functions in Visual FoxPro

How does one write a Variadic Function in Microsoft Visual Foxpro? A variadic function is one that accepts a variable number of arguments - see http://en.m.wikipedia.org/wiki/Variadic_function. Examples are given for just about every other…
1
vote
2 answers

What does `(...)` mean when defining a macro?

I discovered this in the source code for the Unreal Engine 4 and didn't recognize it. The specific instance of it is: #undef UCLASS #define UCLASS(...) \ ARadialForceActor_EVENTPARM I'm a fairly new programmer and this kind of macro is unfamiliar…
Max North
  • 13
  • 2
1
vote
2 answers

Why "vsprintf" is getting stuck when calling a function from a macro using __VA_ARGS__?

I have the following macro: #define TRACE__LOW(str, col, ...)\ TR_Trace("\r\e[" COLOR(col) "%s :: %s():%d; LOW - " str "\e[0m\r\n",\ ##__VA_ARGS__); And the function TR_Trace looks like this: void TR_Trace(const char *const string,…
m4l490n
  • 1,592
  • 2
  • 25
  • 46
1
vote
2 answers

Tricking Preprocessor VARIADIC MACROS in GCC

I have a task at work to make the static library more secure , in order to do so I need to replace the formatted strings of printf for them to appear differently in the compiled static library , for this to happen it must be done in the pre…
Fluffy
  • 337
  • 1
  • 5
  • 16
1
vote
1 answer

Generate array using variadic macros

I want to generate an array of function pointers using a variadic macro. Here's an example. Before preprocessing: #define MY_MACRO(mClassName, ...) ??? struct test { void a() { } void b() { } void c() { } }; MY_MACRO(test, a, b,…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
1
vote
1 answer

Checking if an argument is passed in variadic macros in C

For cleaner error handling I use a macro (it uses C99 and GCC extensions); the behavior is like standard assert: #define A(cond, msg, ...) ({ \ if (!(cond)) { \ if (msg) \ say(msg, ##__VA_ARGS__); \ …
user1150105
1
vote
2 answers

C++ variadic macro and template

I am playing with variadic macro and template. Is there any simple way to achieve the following? It's like std::make_tuple. How to implement make_my_class? I saw I probably need "std::decay" but I don't quite understand that. Thanks a lot in…
alex
  • 193
  • 2
  • 8
0
votes
0 answers

How to get this expected behavior using MSVC macros?

The behavior i want #define E() E2(k) #define E2(k) printf("%d", k); #define A A2(__COUNTER__) #define A2(k) E() A I would like to E() expands FIRTS to E2(k) in the line #define A2(k) E(). Then the result would be printf("%d", some_number); The…
0
votes
2 answers

How can a variadic macro with a list of types produce a function which accepts those arguments and passes them along?

I have a macro: #define WRAP_FUNCTION(wrapper_name, function, ret_type, arg1_type, arg2_type, ...) And I would like it to define a function like this: ret_type wrapper_name(arg1_type arg1, arg2_type arg2, ...) { return function(arg1, arg2,…
sh1
  • 4,324
  • 17
  • 30
0
votes
1 answer

How can I use DataTypes key as arguments

I have a macro that works as expected, but I want to make some changes to make it cleaner to use. #define FuncCreate(func_name, func, ...) \ int func_name(lua_State *ms) { \ func(__VA_ARGS__); \ return 0; \ } FuncCreate(appEvent,…
0
votes
0 answers

How is stdarg Provided in the C++ Runtime

Background: While setting up YouCompleteMe compile arguments for a standalone GCC + sysroot for aarch64, I went spelunking in the standard C++ system includes and found this little gem: [sysroot]/usr/include/c++/11.2.0/cstdarg #include…
MysteryMoose
  • 2,211
  • 4
  • 23
  • 47
0
votes
1 answer

How to prefix __VA_ARGS__ elements in a macro

Is it possible to prefix each element of variadic parameters with something else? #define INPUTS(...) ??? Function(INPUTS(a, b, c)) should become Function(IN a, IN b, IN c)
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118
0
votes
1 answer

Can an argument follow variadics parameters in C?

Is inserting a terminating argument in send() following the VA_ARGS allowed in the specs? #define VALIST_TERMINATOR NULL #define send(targ, ...)(compile_args(targ, __VA_ARGS__, VALIST_TERMINATOR)) void compile_args(int_t targ, ...) { va_list…
Edwin Skeevers
  • 309
  • 1
  • 8
0
votes
0 answers

Is it possible to overload macros that contain VA_ARGS for logs?

I try overload WriteLogs macro with 1 and 2 params: template void WriteLog(const LogContext& logContext, const LogSettings& logSettings, std::string formatMsg, Args... args) { // ... printf("formatMsg", args...); //…