variadic-macros Questions
13
Solved
Simple question for which I could not find answer on the net. In variadic argument macros, how to find the number of arguments? I am okay with boost preprocessor, if it has the solution.
If it mak...
Cryo asked 23/1, 2010 at 19:11
3
/* 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 head...
Footworn asked 26/9, 2014 at 7:10
2
Solved
I've seen a few questions asking for a variation on a variadic FOR_EACH macro. However unfortunately the answers provided are incompatible with VC++10 due to it expanding __VA_ARGS __ as one argume...
Lynseylynus asked 6/2, 2013 at 15:36
12
Solved
There is a well-known problem with empty args for variadic macros in C99.
example:
#define FOO(...) printf(__VA_ARGS__)
#define BAR(fmt, ...) printf(fmt, __VA_ARGS__)
FOO("this works fine");
BAR...
Terminator asked 7/4, 2011 at 23:39
1
Solved
I have read this article, which illustrates how the __VA_OPT__ function macro can be used to recursively expand a macro. I would like to implement something similar, with the difference being that ...
Wale asked 5/12, 2021 at 22:0
2
Solved
I would like to know what ## does in this macro definition:
#define debug(M, ...) fprintf(stderr,M "\n",##__VA_ARGS __)
I googled for an answer and I came up with the following.
The ## will rem...
Helli asked 19/10, 2018 at 11:32
2
Solved
Consider the following code (live example):
#define TEST_VA(mX, ...) TEST
#define STRINGIFY_IMPL(mX) #mX
#define STRINGIFY(mX) STRINGIFY_IMPL(mX)
#include <iostream>
int main()
{
std::cou...
Kimmi asked 21/1, 2014 at 18:34
3
Solved
So I've got a macro that works nicely in GCC, but not in Microsoft's C++ Compiler. I'm hoping somebody might know of a workaround, or perhaps can explain to me why it behaves this way.
I'm sure t...
Alisun asked 7/2, 2012 at 21:11
2
Solved
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 pr...
Blubberhead asked 14/12, 2019 at 2:47
7
Solved
I am working on a call macro,
#define CALL(f,...) FN(f)->call((ref(new LinkedList()), __VA_ARGS__))
which when called,
CALL(print,2,3,4,5);
adds 2 3 4 5 to the linked list (, is overloaded...
Arlettearley asked 5/5, 2011 at 0:1
2
Solved
I am aware of the MAP macro that can be used to apply a macro function to a variadic argument list. But how would you apply a macro function to pairs of variadic arguments?
What I want to create i...
Kirschner asked 8/10, 2019 at 2:58
4
Solved
I want to implement a new max/min macro, which can take more than two parameter, for example:
#define max( ... ) ...
and then, I can use it like this:
max( p0, p1, p2, p3 )
max( 2, 4, 100 )
max...
Underdone asked 1/4, 2014 at 1:42
1
Solved
I want to choose one of two functions depending on the number of arguments:
nargs = 0 ----> f1
nargs > 0 ----> f2.
Macros do the following: get the first argument, then if no argument suppl...
Oisin asked 20/7, 2019 at 9:26
2
Solved
I've been looking for a way to check if a variadic macro argument list is empty. All solutions I find seem to be either quite complex or using non-standard extensions.
I think I've found an easy ...
Saltine asked 29/3, 2019 at 12:10
5
Solved
How does this work? How can a C99/C++11 variadic macro be implemented to expand to different things on the sole basis of how many arguments are given to it?
Faroff asked 22/5, 2013 at 3:47
3
Solved
How can I write a macro (for gcc) that would be used like this:
CREATE_STRUCT(my_struct1,foo);
CREATE_STRUCT(my_struct2,foo,bar);
and expands to
struct my_struct1 {
std::string foo;
};
struct...
Florafloral asked 25/4, 2018 at 8:45
2
Solved
I have a simple: #define log(text, ...) fprintf(stderr, "stuff before" text "stuff after", ## __VA_ARGS__); which is triggering: error: ISO C99 requires at least one argument for the "..." in...
Teetotalism asked 16/5, 2017 at 1:22
2
Solved
I want to pass a version string in the compile command:
$ g++ -Wall -D VERSION="2013-12-03 02:15:21, commit cb060df" -o main main.cpp
Inside my code, I have the following:
#define TOSTR_(x) #x
...
Swindell asked 4/12, 2013 at 19:57
1
Solved
Using Paul Fultz II's solution in the post C-preprocessor recursive macro, I'd like to expand an unlimited number of parenthesized macro arguments, e.g.
#define MY_CHAIN (alpha) (beta) (gamma)
...
Diathermic asked 12/3, 2018 at 12:45
1
Solved
Inspired from this kind of solution, I have written below code, which simulates "overloading of macros".
#include<iostream>
#define CONCATE_(X,Y) X##Y
#define CONCATE(X,Y) CONCATE_(X,...
Oatmeal asked 9/2, 2018 at 17:4
1
Solved
I have found no way to merge the first printf into the second:
unsigned get_time_now(void) {return 1;}
#define DEBUG_PRINT 1
#define debug_tcprintf(fmt, ...) do { \
if (DEBUG_PRINT) { \
unsigned...
Countess asked 29/8, 2017 at 17:8
2
Solved
I want to write a load of lines into a C++ file of the form foo(i) for i = 0,1, ... , n, is there a way of doing this at compile time?
I want to do this because I've got a templated class:
templa...
Hargis asked 18/8, 2017 at 14:0
1
How do the va_arg \ va_start \ va_list \ va_end macros work under the hood in x64?
The calling convention in i386 passes parameters on the stack, hence the macro just increments some pointer that p...
Samaniego asked 24/10, 2016 at 10:29
2
Solved
I have these macros which generate error in Visual Studio 2015.
#define log_params __FILE__, __LINE__
#define log(file, line, message, ...) _snprintf_s(nullptr, 0, 0, message, __VA_ARGS__)
Now c...
Undis asked 12/10, 2016 at 17:51
1
Solved
this is the actual macro:
#ifdef DEBUG
#define debug(funcname, format, ...) \
printf(BOLD UNDERLINED REVERSE \
"DEBUG IN " __FILE__ \
" LINE " __LINE__ ":" \
RESET UNDERLINED REVERSE \
...
Contrite asked 26/3, 2016 at 22:5
1 Next >
© 2022 - 2025 — McMap. All rights reserved.