paresh wrote:
yes "<<<" and ">>>" are for marking.
I want to know that the "a = b = c;" statement is valid syntax
according to ISO C.
I ran it myself on various C/C++ compilers it worked. However some one
said to me it is not valid C syntax as
same variable cannot be l-value and r-value in same statement.
Well, let's note first that in `a = b = c`, all the variables are
different, so even if the same variable couldn't be both an
lvalue and rvalue in one statement, it wouldn't matter.
Let's note next that if "some one" really did say that, they'd have
forgotten about statements like `i = i + 1;` (or `i += 1;` or `i++;`).
What I suspect they said, or thought they were saying, is that you're
not allowed [1] to update a variable /more than once/ in a single statement
(actually, before the next sequence point, but that's another discussion),
and if you update a variable, you can only read it in that same statement
(ditto) /for the purpose of determining its new value/.
So `x = x = 0;` isn't allowed. More subtly, `a[i] = a[j] = 0;` isn't
allowed if `i == j`. Also `i = i + i++;` isn't allowed.
Finally, this isn't a matter of /syntax/ -- how to construct larger
bits of program from smaller bits -- at all. It's a matter of /semantics/,
the meaning of bits of programs. The statement `a[i] = a[j] = 0;` is
syntactically fine. Given appropriate definitions for `a`, `i`, and `j`,
its compile-time semantics is fine too -- no constraint violation.
But to be meaningful when it's executed, `i` must not equal `j`, and
this is not a matter of syntax.
[1] On pain of undefined behaviour, ie, the program's behaviour becomes
unpredictable.
--
"There's no 'we' in 'team'." Unsaid
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England