Home >Backend Development >C++ >Can Global Variable Initialization in C Ignore Dependencies?
Global Initialization Order in C : Ignoring Dependencies
Problem:
In a code snippet provided, the order of global variable initialization appears to ignore dependencies. Specifically, the constructor method of a struct is being called before the struct instance is declared.
Answer:
1. Initialization Order of Globals:
2. Dependency Ignorace in Initialization:
Yes, the order of initialization of globals ignores dependencies. This means that a global variable may be initialized before another global variable on which it depends.
3. Ensuring Proper Initialization Order:
To ensure that the constructor of Foo is called before initializing dummy, the following steps can be taken:
The above is the detailed content of Can Global Variable Initialization in C Ignore Dependencies?. For more information, please follow other related articles on the PHP Chinese website!