moraes@CSRI.TORONTO.EDU (Mark Moraes) (12/13/89)
In RISKS-9.50, lai@east.Berkeley.EDU (Nick Lai) comments that indent has an insidious bug under BSD and SunOS. He is wrong about the bug under BSD and SunOS, right about the bug if his compiler is ANSI compliant, but definitely right in pointing out the risk. - On Unix systems, pcc derived C compilers will interpret that code exactly as indent did, generating a warning in the process, so indent's behaviour would not change the intent of the code. (Like the compilers, indent should probably warn the user) Therefore, for old style C, indent's behaviour is NOT wrong. Most old compilers would have treated that code the way indent did, so indent just made the code clearer. - With ANSI C compilers, the =op style syntax is obsolete. This is one of the QUIET CHANGEs in the proposed ANSI C standard -- see section 3.1.5 (Operators) of the Rationale (my copy is dated Oct 31,1988 -- the section number may have changed since) So, if the programmer wrote x=+1; ANSI C compilers would interpret this to mean "assign the value +1 to x". (GNU C version 1.34 on a Sun3 interprets it this way *EVEN* with the -traditional flag) K&R1 C compilers would interpret this to mean "increment x by 1" pcc derived compilers also complain with something like: "foo1.c", line 7: warning: old-fashioned assignment operator "foo1.c", line 9: warning: ambiguous assignment: assignment op taken I don't know if other K&R1 compilers complain this way. (Note that Ultrix 3.1 compilers also follow K&R1 and complain) indent as distributed with BSD and SunOS silently assumes K&R1 C behaviour and converts it to x += 1; GNU indent version 1.1 assumes ANSI C behaviour and converts it to x = +1; Ultrix 3.1 indent does this too (even though their compiler still follows K&R1!) People converting programs from old C to ANSI C should check all code (using grep or some similar tool) to make sure sequences of the form "=op" are converted to "= op" or "op=" depending which is meant! (And make some suggestions on programming style to the person who wrote the code originally)
moraes@CSRI.TORONTO.EDU (Mark Moraes) (12/13/89)
Beverly Erlebacher <erlebach@turing.toronto.edu> points out that SunOS4.0 compilers also follow ANSI, and interpret =op as = op, compiling silently if op is a unary operator. But SunOS4.0 indent works like SunOS3.x/BSD indent and indents according to the old rules, making it op=. So for SunOS in my previous note, please read SunOS3.x.