next up previous contents
Next: Programming Paradigms Up: Modularity and Functions Previous: Modularity and Functions   Contents

Data Structures

Before defining your own structure, check that there isn't already an equivalent one available within your existing environment. If there is you should use it as this will directly add to the resources available to other people. Defining your own structure will actually prevent code re-use.

All new data structures should have an associated memory alloction and free function which should be carefully tested to avoid error leaks (put them in the same C file so that you can compare and modify them consistently). Once written this function should ALWAYS be used to generate and free the structure.

Integration with other software libraries is generally simple and can be done at a number of levels. The simplest (though slowest and most clumsy) involves writing wrapper functions to convert data between data structures in order to allow use of externally defined functions. A better method involves modifying equivalent data structures to achieve a common definition. The clean separation of data strutures and algorithms inherrent in C programming makes this possible by gradual re-definition of structures using automated search and replace2.2. A test program should be used at all stages, though the compiler will generally spot most errors.


next up previous contents
Next: Programming Paradigms Up: Modularity and Functions Previous: Modularity and Functions   Contents
root 2017-09-20