P
paresh
Is this the valid C statement.
int a,b,c;
c = 5;
<<<
a = b = c;
Can anyone throw the light on this.
-Paresh
int a,b,c;
c = 5;
<<<
a = b = c;
Can anyone throw the light on this.
-Paresh
Is this the valid C statement.
int a,b,c;
c = 5;
<<<
a = b = c;
Can anyone throw the light on this.
Is this the valid C statement.
int a,b,c;
c = 5;
<<<
a = b = c;
Can anyone throw the light on this.
paresh said:Is this the valid C statement.
int a,b,c;
c = 5;
<<<
a = b = c;
Can anyone throw the light on this.
int a,b,c;
I want to know that the "a = b = c;" statement is valid syntax according
to ISO C.
paresh said: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.
paresh said: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.
It is valid syntax. What is more, the semantics are well-defined too.
First, if this were forbidden (it is not) it would not be classed as
invalid syntax. Syntax (in C) is just about the "shape" of the code;
what sort of things can go where. Second, you were told something the
"same variable" and all yours are different so what was said has
nothing to do with your example. Third, what this person said is
obviously false, unless you think that C forbids:
x = x + 1;
in which x is used both as a lvalue and as an r-value (C does not use
the term rvalue be we can reasonably assume what was meant).
paresh said: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.
So what is the term used for rvalue in C?
Dont you think "b" is behaving as a lvalue and rvalue(whatever it is
called).
paresh said:Thanks Chirs for your explanation.
That means "a=b=c;" is valid syntactically and semantically.
However if execution of the statement is right to left then it seems
that it will do what we are expecting.
On the other way (i.e left to right) it will mess up the variable "a".
Is "right to left" or "left to right" execution depends on the
compiler or its a standard?
paresh said:Thanks Chirs for your explanation.
That means "a=b=c;" is valid syntactically and semantically.
However if execution of the statement is right to left
then it seems
that it will do what we are expecting.
On the other way (i.e left to right) it will mess up the variable "a".
Is "right to left" or "left to right" execution depends on the
compiler or its a standard?
paresh said:That means "a=b=c;" is valid syntactically and semantically.
However if execution of the statement is right to left then it seems
that it will do what we are expecting.
>
On the other way (i.e left to right) it will mess up the variable "a".
Is "right to left" or "left to right" execution depends on the
compiler or its a standard?
Yes, if we executed
(a = b) = c;
we'd have undefined behavior, because we are attempting to modify 'a' more
than once between two sequence points.
paresh said:Thanks Chirs for your explanation.
That means "a=b=c;" is valid syntactically and semantically.
However if execution of the statement is right to left then it seems
that it will do what we are expecting.
On the other way (i.e left to right) it will mess up the variable "a".
Is "right to left" or "left to right" execution depends on the
compiler or its a standard?
Is this the valid C statement.
int a,b,c;
c = 5;
<<<
a = b = c;
Can anyone throw the light on this.
-Paresh
I am not sure why you ask the question, but the fact you ask it at all
tells me you should likely be keeping it dead simple and doing
assignments separately as you mean them to be done.
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.