October 06, 2004
"Sanel" <Sanel_member@pathlink.com> wrote in message news:ck0r7b$2cjq$1@digitaldaemon.com...
> You are right, but when you try to port code written for other compilers,
this
> become annoying.
>
> What Walter say about this ?


There is no consensus among C++ compiler vendors on what things should be warnings and what things shouldn't be. In fact, sometimes warnings are contradictory - adjusting the code to not warn with one compiler will cause a warning with another. This is why warnings can usually be individually turned on or off with compiler switches.


October 06, 2004
Sanel wrote:
> Yes,
> but there should be silent implicit comparison. For example, GCC with -Wall
> option
> does not say anything and i am thinking that warning for obvious expression should not be.

IMHO gcc gets this wrong. It doesn't warn about the following if statement:

    if(!(a = b && c == d))

which is probably a mistake. To be able to do what you want, and get something like this right, is not easy.

Interestingly g++-3.4 seems to have dropped the warning completely - although, I don't think I've got the latest version, so it might have changed.

Personally, I try to avoid using the return value of an assignment, so I appreciate the warning.

Daniel
October 06, 2004
>I saw that! IMO the ! operator should be enough to suppress the warning. My extra note was that the warning could also be suppressed by the parenthesis around the assignment.

Try it. ;)

>Right, it's the way the compiler issues warnings. Warnings are not necessary errors, that's why files with only warnings still compile. It's only a hint to the programmer that he might have intended something different.

That is ok, but if we get warning for every little bit odd expression where we will go.

To stop this confusion, here is the statement from standard:

"The value of a condition that is an initialized declaration in a statement other than a switch statement is the value of the declared variable implicitly converted to type bool."

and

"The value of a condition that is an expression is the value
of the expression, implicitly converted to bool, for statements other than
switch..."

>switch -w2 or change the code a bit.


>Don't know. I appreciate warnings.

Good warnings are bless.

Sanel

>
>- Heinz


October 07, 2004
Hello,

Sanel wrote...
> >I saw that! IMO the ! operator should be enough to suppress the warning. My extra note was that the warning could also be suppressed by the parenthesis around the assignment.
> 
> Try it. ;)

Yes, DM issues a warning. In my opinion the warning could be suppressed in this case because with the parenthesis the programmer tells the compiler that he knows what he is doing.


> To stop this confusion, here is the statement from standard:
> 
> "The value of a condition that is an initialized declaration in a statement other than a switch statement is the value of the declared variable implicitly converted to type bool."
> 
> and
> 
> "The value of a condition that is an expression is the value
> of the expression, implicitly converted to bool, for statements other than
> switch..."

That's all right and DMC doesn't reject the valid code. It only gives a warning. The standard doesn't tell anything about warnings, only about errors that must be detected by the compiler.


> >switch -w2 or change the code a bit.
> 
> 
> >Don't know. I appreciate warnings.
> 
> Good warnings are bless.

Ack!


- Heinz
1 2
Next ›   Last »