1.6 ARCHITECTURE OF ‘C’ PROGRAMS (TOP-DOWN)

 

1.6.1 How?

• A program should be broken into fundamental parts (using functions for each part) and then assembled using functions. Each function consists of programs written using the previous simpler functions.

 

 

• A Clear division should be maintained between program levels.

 

• Never use goto’s, they are a major source of logic errors. Functions are much easier to use, once written.

 

• Try to isolate machine specific commands (like graphics) into a few functions.

 

1.6.2 Why?

• A top-down design allows modules to be tested as they are completed. It is much easier to find an error in a few lines of code, than in a complete program.

 

• When programs are complete, errors tend to be associated with modules, and are thus much easier to locate.

 

• Updates to programs are much easier, when we only need to change one function.

 

• It is just as easy to change the overall flow of a program, as it is to change a function.

Application of ‘C’ to a CAD Program