Precedent for use of =

daveh at cbmvax.UUCP daveh at cbmvax.UUCP
Sat Jul 12 01:48:09 AEST 1986


> 
> Unfortunately, it's that kind of attitude that leads to the perpetuation of
> bad language constructs.
> 
> C's handling of assignment and equality is a problem: it is error-prone.
> What's worse is that one often sees code like "if (a=b)" done on purpose--
> yet another example on how the "power and terseness" of C leads to
> obfuscation.
> 
> C. Wingate

Hey, you can use assignment in C as if it were a statement only when you
write YOUR C code, but in the example that you give its used in its full
power as an operator, which can generate much more efficient code than
the equivalent:

a=b
if (b)

Personally, I would have coded it

if ((a=b) == 0)

OR

if ((a=b) == NULL)

to make my point clear (a good compiler will produce the same code in all
three cases, though a bad one may code more efficiently on the first
example).  But my point is that there's nothing inherently bad about the
constructs available in C, there's no confusion if you know the language
and don't specifically try to write confusing code (which you can do in
languages like APL and LISP much more effectively than in C), and there's
additional power in the language for those who know how to use it.  You
like the verobsity of Pascal, so use Pascal.  I like the power of C, 
which is why I write in it, and I'm not confusing MYSELF with C.  Giving
Pascal's rules to a good C programmer is like giving a dull scapel to a
skilled surgeon; he can't cut himself with it.


-- 
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Dave Haynie    {caip,ihnp4,allegra,seismo}!cbmvax!daveh

	"I don't feel safe in this world no more, 
	 I don't want to die in a nuclear war,
	 I want to sail away to a distant shore
	 And live like an ape man."
				-The Kinks

	These opinions are my own, though for a small fee they be yours too.
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



More information about the Comp.lang.c mailing list