Re: "Statement with no effect" warning
Re: "Statement with no effect" warning
- Subject: Re: "Statement with no effect" warning
- From: glenn andreas <email@hidden>
- Date: Fri, 22 Jun 2007 09:54:36 -0500
On Jun 22, 2007, at 9:38 AM, Michael Stauffer wrote:
The comma operator is a trap for the unwary. Lose it.
Huh?
The comma operator is almost never necessary, and it often
obfuscates the code. Unless it is absolutely necessary, it is
best avoided.
Makes me realize I didn't even know what a comma operator is, have
never
used one. The "left-hand operand of comma expression..." warning I
mentioned
above is generated when a debug logging statement is defined as
empty for
release builds. So the comma expression is actually part of an
abandoned
parameter list.
Cheers,
Michael
Then you probably have your macros set up incorrectly, because if one
of those parameters happens to be a function call with side effects,
they will still happen.
If you're doing something like:
#ifdef DEBUG
void SomeDebug(FILE *f, int y) {
}
#else
#define SomeDebug
#endif
then doing:
SomeDebug(OpenMyLog(), 5);
is problematic, since it will create:
(OpenMyLog(), 5);
which would give you those compiler warnings, as well as call a
function that may have a bad side effect (in this case, open a file)
Instead, you should do:
#define SomeDebug(x, y)
(which will swallow both the parameters).
If the thing is has a variable number of parameters such as:
void LogDebug(const char *fmt, ...)
you can use the following:
#define LogDebug(...)
to define a pre processor macro that has a variable number of
parameters (which, in this case, is again swallowed and ignored) -
see <http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html>
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | flame : flame fractals & strange attractors : build,
mutate, evolve, animate
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden