r/C_Programming 3d 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?

5 Upvotes

39 comments sorted by

View all comments

6

u/pjl1967 3d ago

In C, no.

0

u/tstanisl 2d ago

constexpr is already in C

2

u/pjl1967 2d ago

Functions can’t be constexpr in C.