This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Too many warnings.


Phil Edwards wrote:
> >       i++ && (j=84);
[snip]
> The compiler is doing the correct thing here.  It's not the i++ nor
> the (j=84) that's causing the complaint.  It's the result of the 
> && expression, that is,
> 
>     (truth value)  &&  (truth value)
> 
> yields another truth value, and /that/ isn't being used.  If you
> declare another int, say 'q', and assign to it,
> 
>     q = i++ && (j=84);
> 
> the warning goes away.

I do understand that there is a value being ignored here.  But that is
true for the statement

  i=1;

too.  The value of the expression (i=1) is 1, but that is ignored.

Without knowing much about the internals, I understand the situation
like this:

The compiler doesn't warn about the any value being ignored in "i=1;"
since it is reasonable to ignore the value.  The evaluation of the
expression does have a sideeffect, and the user wants the sideffect to
happen.  That is the reason for the statement.

Similarily, the evaluation of my expression

  i++ && (j=84)

does have side effects, and the reason for the expression being
evaluated is for these side effects to happen.  It is reasonable to
ignore the resulting value, for exactly the same reason as above.  So
for the same reason as above, the compiler shouldn't complain about
it.

I hope this was understandable.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]