more questions about efficient C code

John Mashey mash at mips.UUCP
Sun Jun 30 06:58:36 AEST 1985


> > >>	if ((fp = fopen("foo", "r") == NULL) {
> 
> Its its not for the sake of exectution efficiency.  You see it
> a lot for the sake of statement efficiency. ...

It is also useful for human efficiency, once you become accustomed to the
idiom.  Code must be read and understood by humans; less (signifcant, not
{}, (), etc) tokens are generally faster, within reasonable limits.
A similar example is OP= operators; i.e., x = x + 3 requires slightly
longer to read than x += 3, if only because you don't have tyo check that
the variables on the right and left are the same.  Trivial in this case,
but less so when it's  long_identifier1 += 3 instead of
long_identifier1 += long_identifier1 + 3;
No one would claim this is a big effect, but every little bit helps,
especially when it even makes life easier for the compiler.
-- 
-john mashey
UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!mash
DDD:  	415-960-1200
USPS: 	MIPS Computer Systems, 1330 Charleston Rd, Mtn View, CA 94043



More information about the Comp.lang.c mailing list