Re: Problem With Global Variables Initializing
Posted: Fri Aug 28, 2015 11:12 am
I haven't ran in to the issue in a while (yes I fixed my code); and I do set global variables every now and then, but I still prefer to initialize them in code where applicable. But the issue (in my case) was the link.ld script. (which OP is not using according to first post, though another seems he may have changed that)kiznit wrote:What about string constants (error messages for example)? They have to go to a .data or .rodata section (or somewhere). This isn't different from "initializing" globals. They are in fact globals. Note that I am not talking about C++ constructors here (which I wouldn't try to use).BASICFreak wrote:In the world of OSDev I have ran across many random issues I have never seen is userland code for *nix/Win. A lot of the time it is one of the sections of the linked file not being where the rest of the program expects. If you set the variables in the code, it will set the variable where the code THINKS it SHOULD be.
Where do you draw a difference, from a technical point of view, between initializing globals and having string constants in your C/C++ code?
I think that if you run into issues with initialized globals, you have to address these issues whether or not you initialize globals.