Organization of C files

后端 未结 8 1680
悲哀的现实
悲哀的现实 2020-12-13 13:30

I\'m used to doing all my coding in one C file. However, I\'m working on a project large enough that it becomes impractical to do so. I\'ve been #including them together but

8条回答
  •  猫巷女王i
    2020-12-13 14:11

    Try to make each .c focus on a particular area of functionality. Use the corresponding .h file to declare those functions.

    Each .h file should have a 'header' guard around it's content. For example:

    #ifndef ACCOUNTS_H
    #define ACCOUNTS_H
    ....
    #endif
    

    That way you can include "accounts.h" as many times as you want, and the first time it's seen in a particular compilation unit will be the only one that actually pulls in its content.

提交回复
热议问题