All Questions
Tagged with variadic-macros variadic-functions
37 questions
0
votes
1
answer
96
views
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__); ...
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 ...
0
votes
1
answer
1k
views
SPDLOG_LOGGER_CALL and __VA_ARGS__ in
I'm trying to understand why my variadic arguments don't work in spdlog. I understand that there is an SPDLOG_LOGGER_INFO macro to do what I do, but at the moment I need to understand how ...
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
120
views
How to access variable values of a variadic print function?
I am trying to test a function (bar()) which uses a module specific print function (foo_print) to output to the console, seen below:
#define foo_print(...) foo_log(FOO_LOGTYPE_PRINT, ## ...
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 ...
0
votes
2
answers
107
views
C/C++ Variadic Macro Function Overloading
I am trying to build a simple c++ logger for learning purposes, but I seem to be stuck at the following issue. Let's say that I have a namespace that contains two functions as follows:
namespace l {
...
0
votes
1
answer
141
views
Is it possible to get macro passed as optional argument to variadic function using va_arg
I have the below program. It passes a macro as optional arg to variadic function. Within that function definition, shall we able to get that macro without expansion. I have used type as 'char *' and ...
1
vote
2
answers
243
views
is it safe to use va_copy on windows
I have gone through the link https://devblogs.microsoft.com/oldnewthing/20131114-00/?p=2663 for potential pitsfalls using va_list
And below code segment from the same link specifies not to use ...
0
votes
1
answer
191
views
How to do a variadic macro and or template and or function that captures the expression as well as its evaluation?
I have overloaded a class with various << operators
inline QString operator<<(bool boolean) {
return (boolean ? QString("true") : QString("false"));
}
inline QString ...
0
votes
2
answers
1k
views
How to easily create fully "variadic" functions with C++ 98 standard?
The library
https://github.com/c42f/tinyformat/blob/2f9335afd9941688e42d60cae5166b9f0600b2d1/tinyformat.h#L1104-L1116, uses this awesome trick to do "variadic" templates on C++ 98:
inline void ...
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? ...
1
vote
2
answers
168
views
Is this __VA_ARGS__ expansion valid c99?
I am trying to write a function which takes variadic parameters. It has the following prototype:
void foo(const char *name, const char *file, uint32_t line, const char *fmt, ...);
and I call it with ...
1
vote
1
answer
4k
views
too few arguments for class template "std::pair" : Passing std pair as arguments in varidiac function
I have to pass std::pair of std::string to a variadic function. std::pair shows error too few arguments for class template "std::pair" when trying to access std::pair using va_arg macro.
#include <...
1
vote
1
answer
424
views
Is it possible to define a c++ wrapper function for a macro with variadic parameters?
I'd like to come up with a c++ wrapper function that fully wraps the TraceLoggingWrite macro. TraceLoggingWrite is a macro with variadic parameters. I attempted the following code snippet, but it ...
0
votes
1
answer
73
views
Simplifying work with variadic functions / macros
I'm writing a bunch of functions like this:
template <>
Error SyntaxError<unfinished_string>(unsigned int line) {
std::stringstream message;
message << "SyntaxError: ...
1
vote
1
answer
249
views
Wrap macro with variable number of arguments
I need to wrap a macro so that it can be accessed with a function.
The macro is defined like:
#define gDbgLog(fmt,...) dbgLog(g_pdbg,MODULE_NAME,__FUNCTION__,fmt,##__VA_ARGS__)
and I've attempted ...
0
votes
2
answers
164
views
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(...
1
vote
1
answer
575
views
Writing a C macro that takes variadic arguments and also returns a value
I have a use for a macro that displays a message on stderr showing the current filename (from __FILE__) and line number (from __LINE__), but also allows the use of an optional format and variadic ...
2
votes
1
answer
727
views
Limit number of expanded arguments with __VA_ARGS__
I am overloading macros based on the number of arguments, as described in this question :
Overloading Macro on Number of Arguments
When expanded, the __VA_ARGS__ "push" the macro names so that the ...
8
votes
2
answers
2k
views
Variadic function calling a variadic macro
I have an inline variadic function
inline int foo(...)
I need foo() to call a macro (let's call it MACRO), which is also variadic.
Basically I need foo() to pass all its input parameters to MACRO. ...
3
votes
2
answers
1k
views
Overloading macros with variadic arguments
I'm trying to build a macro M which will expand to one of two possibilities, depeding on whether it has one, or more than one, arguments:
M(x)
should expand to
f(x)
While
M(x, "%d%d%d", 1, 2, 3)
...
1
vote
2
answers
1k
views
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. ...
67
votes
3
answers
101k
views
What does __VA_ARGS__ in a macro mean?
/* Debugging */
#ifdef DEBUG_THRU_UART0
# define DEBUG(...) printString (__VA_ARGS__)
#else
void dummyFunc(void);
# define DEBUG(...) dummyFunc()
#endif
I've seen this notation in different ...
2
votes
2
answers
424
views
Is va_start required in variadic arguments for functions?
I'm reading the text The Linux Programming Interface and they show this function to handle errors. In the man pages (man stdarg) it says va_start must be called first to initialize ap for use by ...
1
vote
2
answers
377
views
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 ...
0
votes
2
answers
142
views
Variadic function in C99 to deallocate several arrays?
Currently, I have a very simple function to deallocate array of doubles in my program:
void deallocate(double** array)
{
free(*array);
}
I would like this function to be variadic in order to ...
3
votes
1
answer
2k
views
Visual studio __VA_ARGS__ issue
I run cl /P test.cpp, the file and result is as following.
test.cpp
#define FiltedLog( ...) \
if (logDetail) \
MP_LOG(LOG_INFO, __VA_ARGS__);
#define MP_LOG(level,fmt,...) \
BOOAT::...
3
votes
4
answers
493
views
How can I guarantee type safety of variadic arguments?
In C, I'd like to make a function or a macro that looks like this:
void Log(char* what, ...)
where the ... must be key-value pairs of const char*'s. I would really like code that doesn't follow ...
2
votes
3
answers
4k
views
Objective C - #define using __VA_ARGS__
I am learning how to use macro but now confused with one.
I am trying to create a NSString concatenate which will just append every params to each other.
for example : concatOP(@"hey",@"Jude",@"Don'...
4
votes
6
answers
409
views
Writing a variadic macro that uses the names of the arguments passed
I want to write a variadic macro that somehow knows the names of the arguments passed.
For example:
The code:
int x = 2;
float f = 4.6;
char c = 'A';
char* str = "Bla bla";
PRINT("%d %f %c %s", x, ...
2
votes
2
answers
199
views
"Uninitialised value was created by a stack allocation" when using variadic macro and function
I have the following program http://ideone.com/1RPs8E . It uses a variadic function tlog that will print a line in a log file. It receives a level for the line printed, a file name, a line and a ...
2
votes
1
answer
960
views
Adding extra arguments to a C-style variadic argument list
I'm trying to write a wrapper for a C-style variadic function like printf, which adds some extra arguments, but I'm having trouble with it:
void printf(char* fmt, ...); // the thing I'm trying to ...
4
votes
2
answers
2k
views
How to pass arguments to a variadic macro?
I have a variadic function:
LogWrite(FILE * fp, int level, const char * filename, const char * function, ...)
It should be called like this:
LogWrite(fp, int Level, __FILE__, __FUNCTION__, "Message:...
1
vote
2
answers
447
views
Converting a variadic macro to a variadic template function?
Given a variadic macro of the form:
#define MY_CALL_RETURN_F(FType, FId, ...) \
if(/*prelude omitted*/) { \
FType f = (FType)GetFuncFomId(FId); \
if(f) { ...
1
vote
1
answer
903
views
printf-style logger that is non-variadic
Our C/C++ project is using a new internal script that liberally wraps every function in SWIG to make available to python scripts. It chokes on our logger function since SWIG cannot wrap variadic ...
5
votes
3
answers
8k
views
Adding default arguments to variadic macro
Is it possible to add default arguments before variable argument in variadic macro?
e.g I have the version of macro something like
#define MACRO(arg1, ...) func(arg1, ##__VA_ARGS__)
I would like to ...