Re: chaining statements without a semicolon
I currently have a macro for logging with a definition similar to the
#define LOG shouldLog() && logStream
so that statements of this type may be written:
LOG << "some logging << endl;
I would like to add a static variable to this macro, so that the macro
static LogObject x; x.shouldLog() && logStream
The problem is that with control statements that optionally use braces
(if, while, etc.), the multi statement approach doesn't work. Is there
any way to rewrite this (without adding a brace to the log macro and
creating an END macro) so that everything can be done in LOG?
That's not going to work anyway; you'd need a separate name
for the static variable for each invocation of the macro.
(Of course, something like "static LogObject x ## __LINE_ ;"
might be a solution.) And of course, executing the
constructor the first time you hit the statement in control
flow is going to take time.
What problem are you trying to solve? I've used a static
log object per file in the past, requiring the user to
invoke a macro at global scope to declare it, and referring
to it in the LOG macro. In practice, for small
applications, it isn't necessary; you just use one global
object. And for large applications, the macro which
declares the local object requires an argument, specifying
the subsystem, so you can configure the log differently for
James Kanze (GABI Software) mailto:firstname.lastname@example.org
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34