How to structure #includes in C

后端 未结 6 938
眼角桃花
眼角桃花 2020-12-06 07:48

Say I have a C program which is broken to a set of *.c and *.h files. If code from one file uses functions from another file, where should I include the header file? Inside

6条回答
  •  盖世英雄少女心
    2020-12-06 08:22

    I would only include header files in a *.h file that required for the header file itself. Header files that are needed for a source file, in my opinion, should be included in the source file so that the dependencies are obvious from the source. Header files should be be built to handle multiple inclusion so you could put it in both if required for clarity.

提交回复
热议问题