Uses of "short" ?
Joseph S. D. Yao
jsdy at hadron.UUCP
Thu Nov 14 16:05:33 AEST 1985
Here are some more.
> Make as much static as possible. (No, not electricity.)
Rephrase: restrict the scope of all variables and functions
as much as possible. Use auto's and static's in preference
to extern's.
> Declare all functions which return a value as such.
> If possible, declare non-value-returning functions as void.
> After (not if) you use lint, do as little type-casting as
possible. Instead, take a long look at what you're doing.
Are you forgetting to check return values? Passing more bits
than you can use? ... THEN cast types.
> If you are using an extern in exactly the same way in code
in different functions in different modules, perhaps you can
make a single function to do all of this, and reduce the
scope of the extern.
> Do not use constants in functions. Well, maybe 0.
MAYBE 1 or -1. Never 0 for a null pointer, or end-of-string.
NEVER strings.
> NUL is not NULL. ('\0' and (char *)0 may well be the
same -- but it's not saying what you mean. Or, did you mean
to say that a nul character was the same object as a null
pointer?
> Always check. Your return values. Your pointers. Your
data, before you divide. This is not so much "portability"
as "defensive programming," but what the hey.
More abounds. Want more bounds? Keep asking. ;-)
--
Joe Yao hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
More information about the Comp.lang.c
mailing list