Suppressing Compiler Warning About Tricky Macro

M

Michael B Allen

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
 
R

Robert Gamble

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
 
A

Abdo Haji-Ali

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
 
M

Michael B Allen

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
 
B

Barry Schwarz

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
 
E

Eric Sosman

Michael said:
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);
 
B

Barry Schwarz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top