|
Implementing State Machines
with Examples in C |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
Aside: Enumeration constants have the values \(0, 1, \ldots, n-1\)
which allows us to use the _NUMBER_OF_ idiom.
Note: All of the functions and enumerations have file scope.
if statementsswitch statements (see below)switch Statements
switch Statements (cont.)
Note: current_state has file scope and internal linkage
(because it is decalred to be static)
switch Statements
struct
is used
Note: default_event_handler, default_action
and default_state are extern because they
must be declared in the scope of each individual state but are defined
in states.c.
Note: Each of the individual states are extern because,
though they are declared here, they are defined in the header files
for the individual states.
closed.h and
closed.c
switch
statements?