lkml.org 
[lkml]   [1999]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectC expressions
On Wed, May 05, 1999, "Richard B. Johnson" <root@chaos.analogic.com> wrote:
>
> Lint _clearly_ states that it's an error.
>
Lint isn't and never will be a Standard C compiler. Imagine I wrote this:

#include <stdio.h>
void main()
{
printf("You're code as an error\n");
}

Then apply this program to whatever code you wrote, do you really would
think you're code is actually buggy?
>
> > Finished LCLint checking --- 2 code errors found
>
> Further, previous text states why. Any time I point out these things
> I get a bunch of fanatical "tool gurus" responding that I don't
> know what I'm talking about.
>
You show that you don't know what you're talking about.
>
> [ ... ]
>
> if(a=b)
>
> is that the value of a is not tested. 'a' got assigned the value of
> 'b', but only the assignment was tested, not the resulting value.
>
Obviously, the value of a *is* tested.
Do you remember that, in C, every statement has a value (that could be void)?
That's means:
a=b; which *is* a statement has a value (the assigned value)
that's why
c=a=b; makes a and then c getting the value of b;
because
c=a=b; is *strictly* equivalent to c=(a=b); or (c=(a=b)); or ((c=(a=b));

>
> This, as I explained over and over again, is called a
> "boolean test of assignment error". It is a real error because,
> unless the machine crashed, it is always TRUE. This is what
> Lint is complaining about. One needs to test the result. You
> can do this by adding a sequence-point.
>
I really don't see why you're saying it should always be TRUE.

The only things 'if' does it evaluating what is between the parentheses
and check if is zero or not. And what is in the parentheses is a statement,
and such HAS a value, which for an assignment IS the ASSIGNED value.

The same way
if (a?b:c)
doesn't test if the '?' test succeed (what would that mean anyway?)
but test if (a is non-zero and b is non zero) or (a is zero and c is non zero)
the parentheses aren't needed because a?b:c IS a statement and HAS a value,
the same way as a=b IS a statement and HAS a value.
>
> The obvious way:
>
> a = b;
> |_____ sequence point
> if(a)
>
> Or you combine expressions:
>
> if( (a=b) )
> |_______ sequence point (closed parens)
>
The evaluation of expressions have (hopefully) nothing to do with
sequence points.
>
> Regardless of the flames or comments I will have nothing further
> to say about this.
>
> Cheers,
> Dick Johnson
> ***** FILE SYSTEM WAS MODIFIED *****
> Penguin : Linux version 2.2.6 on an i686 machine (400.59 BogoMips).
> Warning : It's hard to remain at the trailing edge of technology.

I really cannot understand how someone like you, who often write into
this list, doesn't know how a C compiler work. You seam to be a smart man,
so you should have misread the standards.

DindinX

--
David.Odin@bigfoot.com

It has long been an axiom of mine that the little things are infinitely
the most important.
-- Sir Arthur Conan Doyle, "A Case of Identity"

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.069 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site