more about programming style

Richard Welty weltyrp at rpics.UUCP
Thu Aug 1 12:31:40 AEST 1985


> Perhaps I'm being a bit sarcastic, but could it be that the reason experienced
> C programmers often use
> 
> 	if ((fp = fopen("file", "r")) == NULL) ...
> 
> is that the compiler will complain if you write
> 
> 	if ((fp = fopen("file", "r")) = NULL) ...
> 
> whereas it won't complain about
> 
> 	fp = fopen("file", "r");
> 	if (fp = NULL) ...
> 
> ???

Actually, the = vs. == mistake has caused me to take the following
steps ...

1. #define EQ ==

2. NEVER use == directly

3. NEVER make an assignment in an if statement

The result is that any occurance of = in an if is
an error, or a reversion to an older style that should
be corrected.  It does, perhaps, make the code look a little
like fortran, but I've spent one hell of a lot less time on the
= vs. == bug since I started doing this ...

-- 
				Rich Welty

	(I am both a part-time grad student at RPI and a full-time
	 employee of a local CAE firm, and opinions expressed herein
	 have nothing to do with anything at all)

	CSNet:   weltyrp at rpi
	ArpaNet: weltyrp.rpi at csnet-relay
	UUCP:  seismo!rpics!weltyrp



More information about the Comp.lang.c mailing list