Skip to main content
3 votes
3 answers
486 views

Here is the variadic example: https://en.cppreference.com/w/c/variadic.html I want to define two functions but I don't know how to do it correctly. The "foo" function should accept "...
stackbiz's user avatar
  • 1,914
3 votes
2 answers
194 views

I am writing hardcoded calls of functions that takes array(s) in parameter, e.g. int foo(size_t length, const int array[/* length */]); In order to avoid the error-prone process of keeping track of ...
talentless's user avatar
3 votes
1 answer
168 views

There are two classes A and B, each having functions f and g (with the same signatures). The function bool is_A(uintptr_t ptr) returns true if and only if ptr points to an instance of A, and ...
AustinBest's user avatar
0 votes
2 answers
105 views

I would like it so that the function (func parameter) can also take Variable args #define TRY_IT(func, ret, bad_ret_code, give_up_call, ...) \ if((ret) == (bad_ret_code)) { ...
user30507235's user avatar
0 votes
2 answers
162 views

Background I have some macros of the form ATTR(XXX(...)). ATTR processes XXX into a macro ATTR_IMPL_XXX(...), and XXX can have a variable number of arguments (these variadic args are just passed to ...
Anon's user avatar
  • 381
1 vote
0 answers
67 views

In C I wanted to use preprocessor directives inside a macro. Since this doesn't work, I stumbled over this answer about variadic macros, where a macro accepts a varying amount of arguments. The answer ...
codeofandrin's user avatar
  • 1,508
0 votes
0 answers
92 views

It's a pity that there are a lot similar macros(both name and function) in the code below. How to simplify the similar macros? The difference between the similar macros are the string tags, say [...
John's user avatar
  • 3,574
0 votes
1 answer
70 views

Recently, I was working to get and set some fields on a UCI file. To get the failure reason appropriately, I decided to use some macro as given below: #define HANDLE_UCI_ERR(_cond_, _fmt_, ...) ...
Aziz Kavas's user avatar
1 vote
0 answers
139 views

I would like to call two different macros based on whether the macro invocation was with or without parameters. Based on the many examples on SO regarding specific numbers of parameters, I came up ...
bers's user avatar
  • 6,331
0 votes
2 answers
249 views

Is it possible to use a macro or something similar to create instances of a template class and generate the code that then adds the created variables to a std::vector that uses std::variant? Consider ...
Gizmo's user avatar
  • 941
1 vote
2 answers
224 views

While playing with __VA_OPT__(,) I noticed the following behavior. Background First, note that C is fine with trailing commas in an initializer. These are equivalent: int foo[] = { 10, 20, 30 }; int ...
KJ7LNW's user avatar
  • 1,991
0 votes
1 answer
1k views

I am trying to #stringify each token in a __VA_ARGS__ from a variadic macro. The idea is to use these tokens as entries in an enum and also push them (stringified) to a std::vector<std::string>. ...
PinkTurtle's user avatar
  • 7,051
1 vote
1 answer
98 views

I want to implement some function related to reflection in c++, but some issue occurred when I want to expand macro which be concatenated by two macro has been expanded. I try reproducing this issue ...
louis rumor's user avatar
4 votes
1 answer
2k views

Tried to set /std:c++20 or /std:c++latest along /Zc:preprocessor as mentioned in the documentation but Visual Studio refuses to recognize __VA_OPT__ in the following snippet: #define _sdk_log(fmt, ...)...
aybe's user avatar
  • 16.8k
4 votes
1 answer
123 views

I have 2 variadic macros, one of them compiles fine and the other one doesn't: #define ASSERT(x, ...) assert_log(x, __FILE__, __LINE__, __VA_ARGS__) #define TRACE (x, ...) ...
Denis's user avatar
  • 1,667

15 30 50 per page
1
2 3 4 5
21