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

Passing template parameters into macros in MSVC

I am trying to compile C++ code in Visual Studio 2017 that was originally developed on Linux. The project as is compiles on Linux but not in VS. The errors come from trying to use a macro to compare template…
0
votes
1 answer

VC Bug? Compiler Unable to Count __VA_ARGS__' Arguments

Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3 issues errors when compiling the code below. Looks like a bug to me. Thank you. #include #define A( a, b, c, ... ) #__VA_ARGS__ #define B( ... )…
zdf
  • 4,382
  • 3
  • 18
  • 29
0
votes
2 answers

Forward Variadic Argument List to ncurses printw function in c

This has been asked in several different flavors. Yet I can still not get it to work. Here is my function definition. void …
Matthew Hoggan
  • 7,402
  • 16
  • 75
  • 140
0
votes
1 answer

Simplifying work with variadic functions / macros

I'm writing a bunch of functions like this: template <> Error SyntaxError(unsigned int line) { std::stringstream message; message << "SyntaxError: unfinished string (starting at line " << line << ")."; return…
user6245072
  • 2,051
  • 21
  • 34
0
votes
4 answers

How to write a macro in Rust to match any element in a set?

In C, I'm used to having: if (ELEM(value, a, b, c)) { ... } which is a macro with a variable number of arguments to avoid typing out if (value == a || value == b || value == c) { ... } A C example can be seen in Varargs `ELEM` macro for use with…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
0
votes
1 answer

How to define recursive variadic macros?

I am trying to convert boolean values, which represent bits of a signal bus, into an integer. I am using the following construct: #define B_TO_UINT1(b00) (((uint32_t) b00 << 0)) #define B_TO_UINT2(b01, ...) (((uint32_t) b01 << 1) |…
ysap
  • 7,723
  • 7
  • 59
  • 122
0
votes
1 answer

Filtering via macros

I would like to implement a debug printing mechanism that allows both run-time and compile time filtering. Filtering is accomplished via a one-hot encoded mask. Run-time filtering is done by checking the mask within a function. If the level is not…
0
votes
2 answers

Variadic macros with function overloading

I have a function: SendMsg(int x, string y, ...) { /*some code*/ } I have a macro: FOO(X, STRING, ...) SendMsg(X, STRING "%s %d", ##__VA_ARGS__, "xyz", 123) so I can have something like this: FOO(1000, "Note that line %d containing %d words is…
0
votes
1 answer

C variadic macro

I defined two variadic macros below for debug printing. #define MYTRACE(fmt, args...) printf("%s(): "fmt"\n", __func__, ##args) #define MYTRACE_ERR(err, fmt, args...) printf("[ERR] %s(): "fmt" err=%d\n", __func__, ##args, err) Second is the one who…
Ozawa Tomohiko
  • 157
  • 1
  • 1
  • 7
0
votes
2 answers

C99 Macro Expansion for Struct Member Access

Is it possible to do a nullity check and an access in a macro? Eg: #define LOG(mystruct, severity, format, ...) ({ \ severity_t current = ERROR; \ if (mystruct) { \ current = mystruct->error_level; \ } \ if (severity >= current) { \ …
bge0
  • 901
  • 2
  • 10
  • 25
0
votes
1 answer

C++ macro functions with "..." parameter

What does "..." parameter in macro function mean and what does it do? #define ABC(...) some Code Here I don't understand what does this "..." in parameter help with and when should I use them? I have tried goggling about it but all i get is info on…
Karani.pranay
  • 191
  • 2
  • 11
0
votes
1 answer

Number of arguments in macro definition

I have some templated function which has different number of arguments due to the template-type. This function is wrapped with macro definition. #define SomeTemplate(TemplateType, Arguments) someFunc(Arguments); Everything is okay…
Max Frai
  • 61,946
  • 78
  • 197
  • 306
0
votes
1 answer

Need to fix my Variadic Macros

I want to use variadic macros but I get errors #define SERVER_RE_1(ServerFunction, Type1) \ { \ Type1 arg1; …
Ufx
  • 2,595
  • 12
  • 44
  • 83
0
votes
1 answer

How can I check variadic argument __VA_ARGS__ validity?

I wanted to define a macro like - #define log(lognumber,...) logreport(lognumber,__VA_ARGS__) I wanted to check the exception case for __VA_ARGS__ those arguments user can pass when that user calls log() .please provide me exception case for…
0
votes
1 answer

Android - NDK - Variadic macro requiring 1+ args

I have the following macro in a logging library of mine : #define TRACE_E(__logCat,__format,...) \ do { \ ::dbg::LogCategory * const __catPtrVal = (::dbg::LogCategory *)(__logCat); \ if( NULL != __catPtrVal &&…
Virus721
  • 8,061
  • 12
  • 67
  • 123