All Questions
Tagged with variadic-macros variadic
13 questions
0
votes
1
answer
226
views
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)
1
vote
2
answers
256
views
Suppressing warnings for a printf-like function in C++
I have a legacy logging printf-like function in C:
namespace legacy
{
void DoLog(const char* format,...);
}
If is only visible if a corresponding macro is defined (this is legacy too):
#ifdef LOG
...
0
votes
0
answers
102
views
Propagate __VA_ARGS__ macro types inside template methods
I was wondering if there was a clean method to extract types from __VA_ARGS__ and use them to fill template method or structure definitions?
Thanks in advance
I have the following problem:
my macro ...
2
votes
2
answers
3k
views
Calling a printf with __VA_ARGS__ not working in a function but works in a macro
The following macro works:
#define DEBUG(msg, ...) printf(msg, __VA_ARGS__)
But when I add my own function, it says error: '__VA_ARGS__' was not declared in this scope.
My code:
void Debug(const char*...
0
votes
1
answer
305
views
Why does this variadic C function not print the first argument?
I am trying to make a variadic function in C with stdarg.h, and I followed this tutorial and wrote the code exactly as he did: https://www.youtube.com/watch?v=S-ak715zIIE. I included the output in the ...
1
vote
1
answer
56
views
How can have an argument to a function be a type? (Similar to va_arg's second argument)
In the function va_arg for variadic functions, the second argument is just 'type'. When using this function, examples pass something like 'int'. How can I pass and use types in functions of my own? ...
2
votes
1
answer
590
views
Macro for printing variadic arguments, with the option of no arguments
I want to implement the following macro:
ASSERT(condition, ...)
Which is defined like this:
1. If it gets only one parameter - if the condition is false we just print "...
1
vote
2
answers
477
views
macro that defines entire derived class from one function and certain type specifiers?
I have a class called system. A system takes some object managers and changes all objects in them in some way.
For example there might be a system that draws all images in a imageManager.
Every ...
0
votes
1
answer
710
views
C++ - Strip types from parameter list in a macro argument
I have a macro which takes a parameter list as an argument, as shown here:
#define func(returnType, name, args) \
static inline returnType fn_ ## name ## impl args; \
...
0
votes
1
answer
93
views
Passing an arbitrary number of args to a function
So basically, I would like to redefine this part of code using macros,
switch(count) {
case 0:
variadic();
case 1:
variadic(array[0]);
case 2;
variadic(array[0], array[1]);
case 3:
variadic(...
1
vote
2
answers
1k
views
Converting the list of numbers in hexadecimal string in C preprocessor
How to convert the list of the 16bit numbers to the hexadecimal string like "\x0f\x56\x44\xe0".
How do these 16 bit values look? They are the result of the macro expansion too #define make_word(arg1, ...
4
votes
2
answers
3k
views
How to expand macro and delete comma
For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments:
#define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), ...
0
votes
2
answers
3k
views
How to use Variadic macros with fprintf
I am trying to print logs into a file by writing macros.
My macro looks like as shown below:
#define LOG(fmt,...){\
FILE *F;\
F = fopen("output.txt","a");\
fprintf(F,fmt " %s %d",...