[net.lang.c] Subtle C's

lwe3207@acf4.UUCP (04/12/84)

Nf-From: acf4!lwe3207    Apr 22 12:17:00 1984


[]

Sorry -- somebody accurately pointed out to me that they *are* equivalent.
I had assumed that they were (because I had some other bug in my program),
without testing the inequivalence.  It didn't occur to me that semicolon
followed by "if" had a different precedence than semicolon elsewhere.

lwe3207@acf4.UUCP (04/12/84)

Nf-From: acf4!lwe3207    Apr 22 12:18:00 1984


[not my day]

For "if" in the correction read "else".

lwe3207@acf4.UUCP (04/22/84)

Nf-From: acf4!lwe3207    Apr 21 18:30:00 1984


[]

Another subtle non-equivalence:

	while (a) if (b) foo; else bar;

is not a syntax error, but is not equal to

	while (a) { if (b) foo; else bar; }

dmmartindale@watcgl.UUCP (Dave Martindale) (04/23/84)

		From: lwe3207@acf4.UUCP
		Message-ID: <13900003@acf4.UUCP>
		Date: Sat, 21-Apr-84 18:30:00 EST

		Another subtle non-equivalence:

			while (a) if (b) foo; else bar;

		is not a syntax error, but is not equal to

			while (a) { if (b) foo; else bar; }


1) If they aren't equivalent, what *is* the first one equivalent to?

2) Please tell us what compiler you are using when you make statements
   such as this.

For the record, the 4.2BSD PCC-based compiler *does* treat the two
statements as equivalent, and I cannot see any other interpretation
allowed by the language.  The "else" must be part of the if statement.

jim@ism780.UUCP (04/26/84)

#R:acf4:-1390000300:ism780:12500004:000:474
ism780!jim    Apr 25 10:26:00 1984

> Another subtle non-equivalence:
>
>         while (a) if (b) foo; else bar;
>
> is not a syntax error, but is not equal to
>
>         while (a) { if (b) foo; else bar; }

You are wrong.  These are equivalent according to
a) C syntax rules.  b) pcc generated code.  c) common sense.

There are a lot of people on this net who act like they know what they
are talking about, but don't.  BEWARE OF FALSE WIZARDS!

-- Jim Balter, Interactive Systems (decvax!yale-co!ima!jim)

Anonymous@inmet.UUCP (05/05/84)

#R:acf4:-1390000300:inmet:5000014:000:632
inmet!Anonymous    Apr 26 09:09:00 1984

[]

> Another subtle non-equivalence:
> 
> 	while (a) if (b) foo; else bar;
> 
> is not a syntax error, but is not equal to
> 
> 	while (a) { if (b) foo; else bar; }

OK, I give up.  What's the difference?  According to my copy of K&R, they
both have only one parse, and they differ only by the compound-statement
step in the second example.  Thus they shouldn't be different in meaning.
Is there some C compiler that generates different code?  I'd call it a bug.

					John M Chambers [inmet!jc]
					Intermetrics, Inc.
					735 Concord Ave.
					Cambridge, MA 02138
"I don't have any solution but I certainly admire the problem."