This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to divide my complete c code into small c codes.

i have written the C code complied it with 0 error and 0 warnings.

now how can i divide this codes into small c codes in same project.

please help me as i am new to embedded world

Parents
  • I think a prime example of Coincidental Cohesion is to put all your globals from the whole project into one file called "globals.c" - with a corresponding "globals.h"...

    one file with the following

    #if ralph
    #define fido extern
    #else
    #define fido
    #endif

    and all definitions/declarations preceeded by fido

    then in one .c file
    #define ralph

    Erik

Reply
  • I think a prime example of Coincidental Cohesion is to put all your globals from the whole project into one file called "globals.c" - with a corresponding "globals.h"...

    one file with the following

    #if ralph
    #define fido extern
    #else
    #define fido
    #endif

    and all definitions/declarations preceeded by fido

    then in one .c file
    #define ralph

    Erik

Children
  • #if ralph
    #define fido extern
    #else
    #define fido
    #endif
    
    /*there should be an*/
    #undef ralph
    /*here, to avoid nasty side effects from multiple inclusion
    

    Let's note that most people still using that "trick" actually call that fido "EXTERN" or some variation of that to make it at least marginally self-explaining.

    But it's still a half-baked idea. For starters, it breaks down as soon as you want to have explitly initialized globals use the same scheme. It also upsets various kinds of static analyzers that hate it when the same header expands to different things in different translation units.