r/C_Programming • u/heavymetalmixer • Sep 11 '26
Question Unmodifiable globals initialized from functions?
Right now I'm trying to use Windows's SYSTEM_INFO to initialize 2 global constants, but global constants can only be initialized with constant expressions so this cannot be done.
Is there a way I can have "read-only" global variables that can be initialized from functions?
6
Upvotes
View all comments
Show parent comment
1
u/WittyStick Sep 12 '26
I get what you're saying, but for this use case it really does not matter. The purpose of the check is simply to prevent someone else, other than the initialization code from setting the value. It will already be set before any other use code could call it.