Closed Bug 16196 Opened 25 years ago Closed 25 years ago

PR_LOG() when optimized, generates undesirable code

Categories

(NSPR :: NSPR, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: larryh, Assigned: larryh)

Details

Jerry Kirk <Jerry.Kirk@NexawareCorp.com> reports the following:

I am tracking down a bizarre bug and ran across this question, Say you have this
code snippet...

if (mWidget)
  PR_LOG(FooBarLog, PR_LOG_DEBUG, ("2b |! 2b that is the question %d",
mWidget->Width));
printf("Hello World\n");

If this is compiled with DEBUG then the PR_LOG gets expanded and surrounded by
do {
}while (0);

but if DEBUG is off and logging is off then PR_LOG just gets defined as nothing
which I think would cause the  printf to be associated with the "if" or am I
totally wrong... When logging is off shouldn't PR_LOG be defined as a ";" or a
"BEGIN_MACRO END_MACRO" ?

...
This does appear to be a bug.
The macro for PR_LOG() will be changed to something that will compile to the
desired result. ... The change will be made after the merge of NSPR 3.5 to the
mozilla tree, probably on or after 13-Oct-1999.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
This is not a problem.

Follow up my own post. ... On further examination, the code is correct. On the
assumption that  you coded the PR_LOG() with a trailing semi-colon, then the
semi-colon is emitted, which closes the if()statement. In the DEBUG build, if
you do not have the statement ending semi-colon, you get compiler error because
the "}while(0)" must have the closing semi-colon to be syntacically correct. In
the Optimized build, the closing semi-colon after the PR_LOG() is emitted even
though nothing else is emitted.

The macros for PR_LOG() are correct as provided.
You need to log in before you can comment on or make changes to this bug.