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
0
votes
1 answer

Variadic template counting arguments with ellipsis passed as argument

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(...)…
Zach Saw
  • 4,308
  • 3
  • 33
  • 49
-1
votes
1 answer

Is there a way to select between two macros depending on the number of parameters on a function sent as the macro parameter?

I realize the title of the question is very confusing, but I cannot think of a better way to word this, so I'll explain it better with code. I know you can select macros based on the number of parameters it receives using macro expansion and…
-1
votes
1 answer

most succinct or canonical way to bind class members for purposes of input, output, etc. using power of modern C++

My application requires end-users to write some classes to which I'll feed input data and take output data from. These user classes can be subclasses of a base class I provide. A way that's worked since the 90s would be a template allowing members…
-1
votes
2 answers

_Generic function with several parameters

I am using several similar functions and want to make one overloadable. The basic function takes 3 parameters, and its successive expansions take 4 or more. #define register_read_write(action, parameter, reg_value, ...) …
-1
votes
1 answer

initialize specific array elements using macros

I have data file which i want to load during preprocessing . DATAFILE : CAR(C1, C2, C3) There can be n number of cars (C1, C2....Cn), currently 3. The C1,.. are enums fields with specific value say C1=5, C2-8, c3-10. I want to populate this data…
CodeTry
  • 312
  • 1
  • 19
-1
votes
2 answers

Why does a variadic macro give me an error?

Given this sample code: #define vX(a, ...) ((a)(__VA_ARGS__) ? 1 : 0) { int f(); vX(f); } I get error C2155: '?': invalid left operand, expected arithmetic or pointer type On the other hand if I provide a second argument to the macro it…
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
-2
votes
3 answers

Why are variadic macros so unpleasant?

Variadic macros in CPP (the C/C++ preprocessor; for simplicity's sake I'll treat it as a single, separate language in this question) are extremely limited compared to, e.g., C++'s variadic templates. Essentially, variadic macros are just macros with…
Sneftel
  • 40,271
  • 12
  • 71
  • 104
-2
votes
1 answer

Function Definition Generation from Declaration using Template Metapogramming

C++ gurus, I have a template metaprogramming question. Consider the following function declaration. int foo(const int x[], char *y, size_t size); I would like to be able to generate the function body as follows: int foo(const int x[], char *y,…
-3
votes
3 answers

Variadic macros didn't work

What I want to do is access code with macros. But the complier gives me this error identifier "BUTTON___button" is undefined #define BUTTON_1 HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_8) #define BUTTON_2 …
user9018881
-3
votes
1 answer

C variadic macro do not compile

I have some issue with this code i written. GCC does not like it : #define _DEBUG_ADD(string, ...) \ do{ \ if (EVALUATE_TYPE(string)){ \ size_t size =…
1 2 3
19
20