Should variable definition be in header files?

后端 未结 4 1381
一整个雨季
一整个雨季 2020-12-01 10:30

My very basic knowledge of C and compilation process has gone rusty lately. I was trying to figure out answer to the following question but I could not con

4条回答
  •  不思量自难忘°
    2020-12-01 11:30

    Header guard protects you from multiple inclusions in a single source file, not from multiple source files. I guess your problem stems from not understanding this concept.

    It is not that pre-processor guards are saving during the compile time from this problem. Actually during compile time, one only source file gets compiled into an obj, symbol definitions are not resolved. But, in case of linking when the linker tries to resolve the symbol definitons, it gets confused seeing more than one definition casuing it to flag the error.

提交回复
热议问题