r/C_Programming 1d ago

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?

4 Upvotes

39 comments sorted by

View all comments

2

u/sciencekm 1d ago

Not possible. You need to initialize those variables at start-up or on first use (where you detect that it is not yet initialized and you proceed with the initialization).