down

H.L. Stahl hls at rwthbs.UUCP
Mon Dec 12 21:47:32 AEST 1988


In article <gables.352 at umigw.miami.edu> slores%gables.span at umigw.miami.edu (Stanislaw L. Olejniczak) writes:
>PLEASE don't flame for posting too simple a question.  I think the following
>SHOULD work, but will not even compile:
>	while ( (c = getchar) != EOF)
>		chcnt++ += (c == '\n');
>... this would be too complex for a compiler. ...

The answer is quite simple: "+=" is an assignment operator, on it's left side
are only "lvalue"s allowed. But "chcnt++" is an expression with the result
"1 + previous_value(chcnt)", and you cannot assign anything to an expression,
even in C ...

I hope this helps!

Hans-Ludwig Stahl



More information about the Comp.lang.c mailing list