Getting Started

(lily) #1

Chapter 6: C Functions and Program Structures


e compiler as a separate first step.

ld be a good time
e them to prevent name conflicts. We saw in the discussion
orget that you have declared a variable name as
able using a name in another file causing
ou consider it fun to stay up all night to find a
likelihood of such is to keep a single header file
gram. For instance, if we decide to build a Killer
write different C sources files for the various

s.c

ylonEnemyDiscriminator.c

.c to substititute ‘theProgrammer’
er learning that bugs yield extreme

tells the preprocessor to substitute a specified arbitrary
uence of characters anywhere it sees a specific token:

efine token arb1 arb2 arb3

ich causes the complier to substitute ‘arb1 arb2 arb2’ everywhere it sees

Preprocessor


The preprocessor runs before th


#include
We have already discussed a little about #include but now wou
to mention how to us
on ‘extern’ that it is possible to f
an extern in one file then define a vari
potential fun results, that is if y
stupid bug. One way to lessen the
for all the C source files in a pro
Cylon Robot, we might wan
mponents we need:


t to
co


CylonEye
CylonLegs.c
CylonArms.c
CylonBlaster.c
C
and so forth...


We could create a header file CylonKillerRobot.h, include it in each of the project
files and use it for all of our variable and function declarations. By putting all the
definitions in this file we lessen the likelihood of creating a name conflict that
causes the code in CylonEnemyDiscriminator
for ‘theEnemy’ leading to the programm
boinking.


#define
The #define directive
seq


#d


Wh
‘token’.

Free download pdf