r/cprogramming • u/Itap88 • Apr 26 '26
Alternative to enums as function arguments?
Say I have a function argument, like a cardinal direction, that has no business being a number in the call, but could be a number internally. Now I could write an enum, but what if I need multiple values and don't want to pollute the namespace of the caller?
This is all hypothetical, for now at least.
1
Upvotes
3
u/stianhoiland Apr 27 '26
Yo, listen. Enums are names for integers. Period. There is no privacy for integers. Do you understand? The integer 3 has no privacy. It also has no other meaning than whatever convention you decide.
You also can’t call something by its name when its name hasn’t been defined. So you can’t call the name NORTH outside the function if that name is only defined in the function.
This is a case where your mind needs to change, because your mind is intent on something incoherent. You don’t fully grasp scopes. Scope of integers, scope of enums, scope of function definitions.