Page 226 - The Art of Designing Embedded Systems
P. 226
A Firmware Standards Manual 21 3
The ANSI C specification restricts the use of names that begin with
an underscore and either an uppercase letter or another underscore
(-[A-Z-][O-9A-Za-z-]). Much compiler runtime code also starts with lead-
ing underscores. To avoid confusion, never name a variable or function
with a leading underscore.
These names are also reserved by ANSI for its future expansion:
E[O-9A-Z] [0-9A-Za-z] * errno values
is[a-z][O-9A-Za-z]* Character classification
to[a-z] [O-9A-Za-z]* Character manipulation
LC-[O-9A-Za-z-] * Locale
SIG[-A-Z] [0-9A-Za-z-l* Signals
str[a-z] [0-9A-Za-z-]* String manipulation
mem[a-z] [0-9A-Za-z-] * Memory manipulation
wc s [ a-z] [0-9A-Za-z-] * Wide character manipulation
Global Variarbles
All too often C and especially assembly programs have one huge
module with all of the variable definitions. Though it may seem nice to
organize variables in a common spot, the peril is these are all then global
in scope. Global variables are responsible for much undebuggable code,
reentrancy problems, global warming, and male pattern baldness. Avoid
them!
Real time code may occasionally require a few-and only a few-
global variables to insure reasonable response to external events. Every
global variable must be approved by the project manager.
When globals are used, put all of them into a single module. They are
so problematic that it's best to clearly identify the sin via the name globa1s.c
or globals.asm.
Portcrbility
Don't assume that the address of an int object is also the address of
its least-significant byte. This is not true on big-endian machines. Thus,
don't make the following mistake:
int c;
while ((c = getchar()) != EOF)
writelfile-descriptor, &c, 1);

