hi all,
i'm trying to switch from gcc,
mainly because PellesC it's very fast on compiling.
Does exist a way, in PellesC, to emulate the variadic macros of gcc?
thanks
paolo
do you mean __VA_ARGS__ ?
Quote from: pber on April 13, 2015, 01:52:54 AM
Does exist a way, in PellesC, to emulate the variadic macros of gcc?
http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html (http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html)
Variadic macros are part of the C99 standard, which Pelles C supports.
So you don't need to "emulate" them as if they're an extension to C.
Example:
Quote#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
thanks, now I see the issue:
gcc allows to pass no arguments in place of <<...>>
i.e.: given
#define f(__fmt, ...) printf(__fmt, __VA_ARGS__)
you can use it with:
f("just a message\n");
but in case PellesC says:
Disagreement in number of macro arguments.
I cant' figure out how to deal with this...
You can simply allow the ellipses (...) to include __fmt, then you can have one argument.
Example:
#include <stdio.h>
#define EPRINTF(...) fprintf(stderr, __VA_ARGS__)
int main(void)
{
EPRINTF("test 1\n");
EPRINTF("%s %d\n", "test", 2);
}
oh gosh.... it was so simple...
many thanks