Should struct definitions go in .h or .c file?

后端 未结 6 1847
死守一世寂寞
死守一世寂寞 2020-12-04 05:26

I\'ve seen both full definitions of structs in headers and just declarations—is there any advantage to one method over the other?

If it makes a differen

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 06:16

    If the struct is to be used by other compilation units (.c files) , place it in the header file so you can include that header file wherever it is needed.

    If the struct is only used in one compilation unit (.c file), you place it in that .c file.

提交回复
热议问题