If you need constants (real, compilation time constants), you can do this in three ways by placing them in header files (there is nothing wrong with that):
enum { FOO_SIZE = 1234, BAR_SIZE = 5678 }; #define FOO_SIZE 1234 #define BAR_SIZE 5678 static const int FOO_SIZE = 1234; static const int BAR_SIZE = 5678;
In C ++, I tend to use the enum method, as it can be placed in a namespace. For C, I use a macro. This, in principle, comes down to the question of taste. If you need floating point constants, you can no longer use an enum. In C ++, I use the latter method, a static const double, in this case (a note in C ++ statics would be redundant then: they became static automatically, since they are constants). In C, I will continue to use macros.
The myth that using the third method will slow down your program. I just prefer the enumeration, since the values you get have rvalues values - you cannot get their address, which I consider to be additional security. In addition, much less boiler room code is written. The eye is focused on constants.
source share