What methods are there to modularize C code?

后端 未结 8 1635
我在风中等你
我在风中等你 2021-02-05 15:48

What methods, practices and conventions do you know of to modularize C code as a project grows in size?

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 16:02

    1. Don't define variables in header files; instead, define the variable in the source file and add an extern statement (declaration) in the header. This will tie into #2 and #3.
    2. Use an include guard on every header. This will save so many headaches.
    3. Assuming you've done #1 and #2, include everything you need (but only what you need) for a certain file in that file. Don't depend on the order of how the compiler expands your include directives.

提交回复
热议问题