Re: C macro for ellipsis(...)
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Wed, 23 May 2007 11:46:49 -0400
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
.
- References:
- Re: C macro for ellipsis(...)
- From: Igor Tandetnik
- Re: C macro for ellipsis(...)
- Prev by Date: Re: vc++ 2005 express support making dll?
- Next by Date: Re: vc++ 2005 express support making dll?
- Previous by thread: Re: C macro for ellipsis(...)
- Next by thread: Re: C macro for ellipsis(...)
- Index(es):
Relevant Pages
|