comma operator

D. Chadwick Gibbons chad at csd4.csd.uwm.edu
Sat Aug 19 16:34:39 AEST 1989


In article <20348 at sequent.UUCP> paulr at crg3.UUCP (Paul Reger) writes:
|Considering the construction:
|
|while ((ch = getchar()) != EOF && ch != '\n')
|
|Is there any assurance in any C standard that the left expression will
|always be evaluated first, with the right following it ??

	It's mentioned in K&R, and most likely the standard; many C programs
rely on the property of boolean evaluation: left to right.  If the first
expression ((ch = getchar()) != EOF is false, there is no need to complete the
second comparison, so the compare falls through.  This is a reliable C
operation.
--
D. Chadwick Gibbons - chad at csd4.csd.uwm.edu



More information about the Comp.lang.c mailing list