Include a header in another header file

前端 未结 5 1777
别跟我提以往
别跟我提以往 2020-12-31 08:43

I\'ve defined a struct item in a .h file. Now I\'m defining another struct tPCB in another .h which is part of the same project, and I need the

5条回答
  •  -上瘾入骨i
    2020-12-31 09:00

    Never ever put variable definitions (that is, allocating them) in a header file. That is bad for many different reasons, the two major ones being poor program design and floods of linker errors.

    If you need to expose a variable globally (there are not many cases where you actually need to do that), then declare it as extern in the h-file and allocate it in the corresponding C file.

提交回复
热议问题