Re: C macro for ellipsis(...)



Lee wrote:
Thank you Igor for your reply.
What I am really doing is to write a function for the error report
with the line # and the source filename.
To be more specific, the above PublicLogWrite() is as follows:

void PublicLogWrite( long nLineNumber, char *szCPPname, char *szFmt,
... ) {
va_list arglist;
va_start( arglist, szFmt );
// ... e.g. vsprintf()
va_end( arglist );
// ... e.g. fprintf() to report lin# and caller's CPP filename.
}

When I wrote it initially, that function didn't have the first two
parameters, and used __LINE__ and __FILE__ inside the function.

I see you got your answer. In case you are curious how one can do it
without variadic macros (e.g. to support VC7), consider this:

struct LogHelper {
int line;
const char* file;

LogHelper(int l, const char* f) : line(l), file(f) {}

void operator() const (const char* format, ...) {
va_list arglist;
va_start( arglist, format );
VPublicLogWrite(line, file, format, arglist);
va_end( arglist );
}
};

#define PrivateLog LogHelper(__LINE__, __FILE__)


For a more elaborate example, see ATLTRACE in atltrace.h
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages