How to use a defined struct from another source file?

前端 未结 7 1983
北恋
北恋 2020-12-06 02:18

I am using Linux as my programming platform and C language as my programming language.

My problem is, I define a structure in my main source file( main.c):



        
7条回答
  •  被撕碎了的回忆
    2020-12-06 02:58

    It is perfectly reasonable to be inclusive with structs by leaving them in the source file instead. This is encapsulation. However if you're going to redefine struct multiple times in multiple source files then you might as well define the struct once in a header file instead and include that file as necessary.

提交回复
热议问题