Subject: Re: KNF and braces (was: Re: EGCS 1.1 UPDATE rev. 4)
To: Todd Vierling <tv@pobox.com>
From: Chris G. Demetriou <cgd@netbsd.org>
List: tech-toolchain
Date: 08/18/1998 11:39:22
[ because the horse is not yet a thin red paste.]

Todd Vierling <tv@pobox.com> writes:
> What egcs "warns" about (or, rather "suggests" in the form of a warning - it
> even starts wit the word "suggest") is something like:
> 
> if (condition1)
> 	if (condition2)
> 		stmt1;
> 	else
> 		stmt2;
> 
> where the hanging "else", while definitely tied to the innermost `if' by C
> parsing convention, is what egcs is warning about.  To avoid the warning,
> you need to brace the entire outer "if".

As far as I'm concerned:

	if (c1) {
		if (c2)
			s1;
		else
			s2;
	}

is good, but:

	if (c1) {
		if (c2) {
			s1;
		} else {
			s2;
		}
	}

is better.  if a programmer adds a statement (e.g. a debug printf) at
a random place, or uses a (poorly-written) macro that happens to be
multiple statements in place of, say, s2, "it all just works."



cgd
-- 
Chris Demetriou - cgd@netbsd.org - http://www.netbsd.org/People/Pages/cgd.html
Disclaimer: Not speaking for NetBSD, just expressing my own opinion.
Plug: Get your official NetBSD-1.3.2 CDROM set today! http://www.netbsd.com/