dcw@doc.ic.ac.uk (Duncan C White) (07/23/90)
Greetings,
I have found a bug in indent.. I hope this is the right place
to report it. If it matters, it was on a Sun 3 running SunOS
4.0.3..
It appears that indent is quite happy to rewrite '=!' as '!='
if you omit a space between the = and the !
Here is a little program which shows the problem:
/*
* Try running this, then run it through indent
* and run it again!
*/
#include <stdio.h>
main()
{
int x = 0;
printf("before: x=%d\n", x);
x=!x;
printf("after: x=%d\n", x);
}
Before running indent, the program correctly prints 0 followed by 1.
After running indent, the program prints 0 followed by 0 (!)
On examination, this is because the x=!x line has been rewritten as:
x != x;
[ie. compare x against itself, and then discard the result]
I know the manual page says that indent has a "forgiving parser" but
really! A parser that rewrites your program for you?
NB: This problem was "enhanced" :-) by lint, which did not flag x != x
as suspicious.
Duncan White.
----------------------------------------------------------------------------
Duncan White, | Doctor: "I'm sure I've forgotten something.."
Dept. Of Computing, | Shopkeeper: "Haven't you forgotten something?"
Imperial College, | Doctor: "Yes..but what?"
London SW7 | Shopkeeper: "Money"
England, | Doctor: "Oh no, that wasn't it"
The Earth. | (wanders off looking puzzled, without paying)
(or Gallifrey?) | Survival episode I, 22nd Nov 1989
iand@labtam.oz (Ian Donaldson) (07/25/90)
dcw@doc.ic.ac.uk (Duncan C White) writes: >Greetings, > On examination, this is because the x=!x line has been rewritten as: > x != x; This sounds like the old C syntax problem that most C compilers *warn* about still. ie: x=-3; used to mean x -= 3; whereas if you really wanted -3 assigned to x you were supposed to put extra spaces in: x = -3; eg: if you compile this with SVR3.2.1 C compiler you get no warnings: main() { int x; x=-3; (void) printf("%d\n", x); return(0); } and running it prints '-3', but if you run SVR3.2.1 lint over the code you see: (5) warning: ambiguous assignment: simple assign, unary op assumed So it looks like the compiler is forgiving but lint still knows the old way things were done. I remember older compilers complaining about such syntax too. Maybe the =! case is similar. Maybe indent should warn about it if it does a conversion. Ian D
karl@haddock.ima.isc.com (Karl Heuer) (07/26/90)
In article <5042@labtam.oz> iand@labtam.oz (Ian Donaldson) writes: >Maybe the =! case is similar. Maybe indent should warn about it >if it does a conversion. No, indent should simply not do the conversion, since `=!' has never been ambiguous. (Even for `=-', this conversion is long obsolete; it should be disabled by default. Welcome to the 1990s, indent!)
gwyn@smoke.BRL.MIL (Doug Gwyn) (07/26/90)
In article <5042@labtam.oz> iand@labtam.oz (Ian Donaldson) writes: -dcw@doc.ic.ac.uk (Duncan C White) writes: -> On exami nation, this is because the x=!x line has been rewritten as: -> x != x; -This sounds like the old C syntax problem that most C compilers *warn* -about still. No, "x=!x" has never been ambiguous; != is not an assignment operator. If "indent" is rewriting "=!" as " != ", then "indent" has a bug.