file scope and static floats

后端 未结 5 1070
无人共我
无人共我 2020-12-10 22:55

I\'ve run into an interesting problem in an AI project of mine. I\'m trying to format some debug text and something strange is happening. Here\'s a block of code:

5条回答
  •  粉色の甜心
    2020-12-10 23:37

    Static variables are linked internally. you can not access a static variable defined in some other source file.
    The situation you are falling into may happen in case when you have defined the static variable TIME_MOD in some header file.Include the same header file in both the input and ratio source files, hence both files have a private copy of the variable TIME_MOD,
    Now the input module changes the TIME_MOD value, but it modifies its own private copy so the value in ratio file remains unchanged and hence your behavior.

    Now if that is the case you do not need a static TIME_MOD, and to resolve name conflicts you may like to use namespaces.

提交回复
热议问题