getc() != EOF

Ed Nather nather at utastro.UUCP
Mon Jun 11 04:42:45 AEST 1984


[]
    >Re the following code:
    >	char c;
    >	while ((c = getc(file)) != EOF);
    >
    >The issue is whether the value returned from the assignment operator
    >should be the value of the left or of the right hand side of the as-
    >signment.  C defines the value to be the value of the left hand side
    >of the assignment. 
    >
    >I contend that this decision was a mistake.
    >
    >				Kenneth Almquist

I disagree.  In my view, the parentheses indicate quite clearly the sequence
of operations expected:

	1. Call getc with the argument "file".
	2. Store the result into the variable location called "c".
	3. Compare that value with the value of "EOF".

The "truncate and store" operation precedes the comparison, and I would be
thoroughly confused if the sequence shown gave a different result from the
(unfolded) sequence

	c = getc(file);
	if(c != EOF)
		...

-- 

                                 Ed Nather
                                 {allegra,ihnp4}!{ut-sally,noao}!utastro!nather
                                 Astronomy Dept., U. of Texas, Austin



More information about the Comp.unix.wizards mailing list