//KM 2018 03 23: getting lots of form spam; screen out dates before 2000 (book publication date) How should I structure my code? | Byte Craft Limited

How should I structure my code?


There are a few rules to follow:

  • Functions that might not get linked in to the final executable should be put in libraries (modules with #pragma library and #pragma endlibrary directives at the beginning and end, respectively). This instructs the compiler to omit generating code for them if they're not invoked.

    Order within the link is important too. Libraries containing any such functions must be linked in after the main program.

  • Note that the above doesn't change the C requirement that functions be prototyped before they are invoked. Your library should have a standard header file with function prototypes.

  • Both headers and program modules should have #ifdef/#define/#endif protection, to prevent compilation errors:

    #ifndef __MODULE_C
    #define __MODULE_C
    /* ... */
    #endif /* __MODULE_C */

    If you've written single-file libraries without this protection, it might cause a problem when compiling using Absolute Code Mode.