Re: [Dev-C++] #define a "function" with variable number of parameters
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel K. O. <dan...@ya...> - 2005-12-19 03:37:51
|
Per Westermark wrote:
>Given the billions of lines of existing code without use of __VA_ARGS__,
>it really isn't such an important function that it is worth it to ignore
>the current language standard.
>
>
Agreed. I was just trying to answer the original question, but I also
doubt that it's really needed.
As Minds Work didn't specify what problem he's trying to solve, I assume
that the example posted could be easily solved with Per's first sugestion.
Something like this:
-----
#include <cstdarg>
#include <cstdio>
#define LOG log_prefix(__FILE__, __LINE__); log
void log_prefix(const char *file, int line)
{
printf("%s:%d:\t", file, line);
}
// here is Per's code
void log(const char *msg,...) {
va_list ap;
va_start(ap,msg);
vprintf(msg,ap);
va_end(ap);
}
int main() {
LOG("test %u %u\n",1,2);
return 0;
}
-----
PS: There's also the C++ way to solve it, using ostreams and operator<<,
that obviously won't need a variable number of parameters.
PS2: if the problem is really just logging, there are tons of C++
libraries that do just this - conveniently. Google a bit, maybe you can
use one of them for your needs.
---
Daniel K. O.
_______________________________________________________
Yahoo! doce lar. Faça do Yahoo! sua homepage.
http://br.yahoo.com/homepageset.html
|