I have a variable in a struct and an initialization routine to set everything up in the structure and get it ready for use by the rest of the program. I have two variables in the structure that I don't want to change. Can I make them constant?
I thought of a possible solution: use a pointer to each of the variables and define them as constants in the structure. Something like this?
It certainly works; but I get this warning from gcc:
warning: initialisation discards qualifiers from pointer target type
(obviously stating that it is not legal to do this), so I won't be able to compile with -Werror.
It's a pretty ugly method; is there a better one? I guess I don't really need it to be constant, but I'd rather it didn't get changed: it could screw everything else up if I acted as though it's value was 4 and it was really 8 or something like that. I'd also rather not waste time checking (in all of seven functions that depend on that struct) with if statements what the value is, also; then I may aswell hardcode the value anyway.
Edit: I can remove that warning with a cast; but I'd still rather find a less ugly method.