首先,我已经扫描了堆栈溢出和网络的其余部分,我很清楚以下内容: 1)全局变量是坏的 2)翻译单元之间的全局变量依赖性不好
但是,我们正在使用一些正在执行以下操作的中间件;我无法确定这是否危险。
// Global_Variable.hpp
#include "Type.hpp" /* this defines the type as a structure, doesn't really matter :) */
extern Type Global_Variable;
// Global_Variable.cpp
#include "Global_Variable.hpp"
Type Global_Variable = { /* init the struct */ };
// Global_Reference.hpp
#include "Type.hpp"
extern Type & Global_Reference;
// Global_Reference.cpp
#include "Global_Reference.hpp"
#include "Global_Variable.hpp"
Type & Global_Reference = Global_Variable; // does this suffer from the SIOF?
// Global_Pointer.hpp
#include "Type.hpp"
extern Type * Global_Pointer
// Global_Reference.cpp
#include "Global_Pointer.hpp"
#include "Global_Variable.hpp"
Type * Global_Variable = &Global_Variable; // does this suffer from the SIOF?
我担心Global_Variable和Global_Reference可以初始化为null而不是Global_Variable,可能是这种情况吗?
谢谢!