By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,611 Members | 1,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,611 IT Pros & Developers. It's quick & easy.

Suppressing Compiler Warning About Tricky Macro

P: n/a
Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);

My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used

Can someone recommend a change that can eliminate these warnings?

I'm drawing a blank.

Mike

[1] LOC0 and LOC1 are not shown expaned for the sake of simplicity
Jul 22 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.comwrote:
Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);

My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used

Can someone recommend a change that can eliminate these warnings?
The warning doesn't appear to be coming from the preprocessor. The
fully expanded version probably contains an expression who value is
discarded, without seeing the fully expanded version (and possibly the
appropriate associated definitions) it is difficult to determine
exactly where the problem is.

Robert Gamble

Jul 22 '07 #2

P: n/a
On Jul 22, 4:52 am, Michael B Allen <iop...@gmail.comwrote:
Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);

My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used

Can someone recommend a change that can eliminate these warnings?
#define MMSG_MODIFIED msgno_loc0(LOC0, LOC1); msgno_mmsg0

OR:

bool bValue = MMSG("foo=%s", foo);

Note that this line:
loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);
(actually should be: msgno_loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s",
foo); )

Calls two functions msgno_loc0 and msgno_mmsg0 which in turn return
(supposably) bool values
These two boolean values are ANDed with the && operator and the final
ADDed value is discarded since you're not
assigning it to another variable nor using it in a if condition.

Abdo Haji-Ali
Programmer
In|Framez

Jul 22 '07 #3

P: n/a
On Sun, 22 Jul 2007 03:38:13 -0000
Robert Gamble <rg*******@gmail.comwrote:
On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.comwrote:
Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

msgno_loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);
^^^^^^corrected

My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used

Can someone recommend a change that can eliminate these warnings?

The warning doesn't appear to be coming from the preprocessor. The
fully expanded version probably contains an expression who value is
discarded, without seeing the fully expanded version (and possibly the
appropriate associated definitions) it is difficult to determine
exactly where the problem is.
Hi Robert,

The LOC0 and LOC1 macros just expand to a filename, line number and
possibly a function name.

The msgno_loc0 and msgno_mmsg0 symbols are functions. Additionally
msgno_loc0 function always returns 1.

What I did do that seems to be ok for now is:

#define MMSG if (msgno_loc0(LOC0, LOC1)) msgno_mmsg0

but in hind sight now I'm not entirely clear as to why I didn't just do:

#define MMSG msgno_loc0(LOC0, LOC1); msgno_mmsg0

Mike
Jul 22 '07 #4

P: n/a
On Sat, 21 Jul 2007 22:52:28 -0400, Michael B Allen <io****@gmail.com>
wrote:
>Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);
No, but hopefully it is just a typo. The left operand of the &&
operator would be
msgno_loc0(LOC0, LOC1)
It is important to cut and paste the code, not retype it.
>
My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used
Look at the above statement. The && operator evaluates its left
operand. If not zero, it evaluates the right operand. If that is
also not zero, the result is set to 1. If either operand is zero, the
result is set to 0. But the result is NEVER used. It is not assigned
to a variable; it is not part of an if/while/?:/for construct. After
going through the trouble of calling the first function, calling the
second function (only if the first returns a non-zero value), and
computing the boolean AND, the result is thrown in the bit bucket,
never to be seen again.

If either of the two functions have side effects, this may be a
reasonable thing to do. However, in general, it's not.
>
Can someone recommend a change that can eliminate these warnings?
There are two obvious (to me) ways to silence the warning.

If you care about the result, assign it to a variable or use
it in one of the conditional constructs.

If you don't care about the result of the expression but only
about the side effects of the function calls, then change the macro to
something like

#define MMSG \
if (msgno_loc0(LOC0, LOC1)) \
msgno_mmsg0

Since you chose to have the arguments to msgno_mmsg0 outside the
macro, you cannot define the macro expansion with the usual
do(...)while(0); construct.
Remove del for email
Jul 22 '07 #5

P: n/a
Michael B Allen wrote:
On Sun, 22 Jul 2007 03:38:13 -0000
Robert Gamble <rg*******@gmail.comwrote:
>On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.comwrote:
>>Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

msgno_loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);
^^^^^^corrected
>>My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used

Can someone recommend a change that can eliminate these warnings?
The warning doesn't appear to be coming from the preprocessor. The
fully expanded version probably contains an expression who value is
discarded, without seeing the fully expanded version (and possibly the
appropriate associated definitions) it is difficult to determine
exactly where the problem is.

Hi Robert,

The LOC0 and LOC1 macros just expand to a filename, line number and
possibly a function name.

The msgno_loc0 and msgno_mmsg0 symbols are functions. Additionally
msgno_loc0 function always returns 1.

What I did do that seems to be ok for now is:

#define MMSG if (msgno_loc0(LOC0, LOC1)) msgno_mmsg0

but in hind sight now I'm not entirely clear as to why I didn't just do:

#define MMSG msgno_loc0(LOC0, LOC1); msgno_mmsg0
Probably because both of these will produce unpleasant
surprises in contexts like

if (phaseOfMoon == FULL)
MMSG("foo=%s", foo);
else
MMSG("bar=%s", bar);

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 22 '07 #6

P: n/a
On Sun, 22 Jul 2007 12:07:33 -0400, Michael B Allen <io****@gmail.com>
wrote:
>On Sun, 22 Jul 2007 03:38:13 -0000
Robert Gamble <rg*******@gmail.comwrote:
>On Jul 21, 10:52 pm, Michael B Allen <iop...@gmail.comwrote:
Hi,

I have a macro that looks like the following:

#define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0

which if used in some code like:

MMSG("foo=%s", foo);

would expand to [1]:

msgno_loc0(LOC0, LOC1) && msgno_mmsg0("foo=%s", foo);
^^^^^^corrected
>
My problem is that the GCC 64 bit compiler complains about this with:

warning: value computed is not used

Can someone recommend a change that can eliminate these warnings?

The warning doesn't appear to be coming from the preprocessor. The
fully expanded version probably contains an expression who value is
discarded, without seeing the fully expanded version (and possibly the
appropriate associated definitions) it is difficult to determine
exactly where the problem is.

Hi Robert,

The LOC0 and LOC1 macros just expand to a filename, line number and
possibly a function name.

The msgno_loc0 and msgno_mmsg0 symbols are functions. Additionally
msgno_loc0 function always returns 1.

What I did do that seems to be ok for now is:

#define MMSG if (msgno_loc0(LOC0, LOC1)) msgno_mmsg0

but in hind sight now I'm not entirely clear as to why I didn't just do:

#define MMSG msgno_loc0(LOC0, LOC1); msgno_mmsg0
Maybe because you subconsciously realized that they are not
equivalent. In the first case, msgno_mmsg0 is called only if
msgno_loc0 returns a non-zero value. In the second, msgno_mmsg0 is
called unconditionally.
Remove del for email
Jul 22 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.