为什么全局变量没有用我在 extern 变量中给出的字符串初始化
//s_request_view() constructor is declared as below
namespace Identity_VIEW
{
Published_view_identity s_request_view("SAMPLE");
};
//The constructor is called in another source file as below,
bind_view(Identity_VIEW::s_request_view);
相同的代码在 Windows 上运行良好,但在 SBC (PowerPC) 上 s_request_view 作为 NULL 传递。
谁能帮我找出为什么它的行为不同?
//s_request_view() constructor is declared as below
namespace Identity_VIEW
{
Published_view_identity s_request_view("SAMPLE");
};
//The constructor is called in another source file as below,
bind_view(Identity_VIEW::s_request_view);
This same code is working fine on windows but on SBC (PowerPC) s_request_view is passed as NULL.
Can anyone please help me finding out why is it behaving differently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想,这里的答案是编译器不保证全局变量初始化的顺序。如果您的 bind_view 是从另一个全局变量的构造函数调用的 - 您将遇到浮动错误。
尝试使用以下方法:
这可以帮助解决全局变量初始化的顺序。然而,这个解决方案不是线程安全的(如果你关心的话)......
I think, the answer here is that compiler does not guarantee the order of global variables initialization. If your bind_view is called from constructor of another global variable - you'll have a floating bug.
Try using the following approach:
That can help resolving the order of the global variables initialization. Nevertheless, this solution is not thread-safe (in case you care)...