Do's:
static
qualifier and should either be defined or fully
declared before their first use in the mdoule.
void
's and enum
's
wherever possible.
extern
.
#if MS_WIN ...or
#endif
#if LINUX ... #endif
enum { Red = 0xF00, Blue = 0x0F0, Green = 0x00F }; static const float pi = 3.14159265358;instead of
#defines
, which are rarely visible in debuggers.
int
int
. If
it returns no value, declare it void
.
makedepend
tools to help maintain
your source file dependencies in your Makefile
.
goto
sparingly. Two harmless places to use it are to break
out of a multilevel loop, or to jump to common function exit code.
Often these are the same places. There are 6 total conditions or programming forms
in which goto
is unavoidable.
if (checksize(s))is unhelpful because we can't deduce whether
checksize
returns true on error or non-error; instead
if (validsize(s))makes the point clear and makes a future mistake in using the routine less likely.
physlim
,
should the bottom be membase
?
Consider the suffix -max
to denote an inclusive limit,
and -lim
to denote an exclusive limit.
gets()
. Use fgets
instead so that
you can be sure that you don't overflow your buffer.
strtok()
and getchar()
(use fgetc() rather than getchar()).