Reputation: 1132
In a multi-source file C application, which is the best place to put constant values, source file itself or in its header file? Provided that constant will be used in that source file only.
Is it a good way to keep static const
in header files?
Upvotes: 5
Views: 1485
Reputation: 16039
Don't expose information you don't need to. If constant is an implementation detail of single compilation unit, there is no need to pollute global namespace. You can always add it to header later if needed.
Depends on the nature of constant. static
creates new constant for each compilation unit header is included in. If constant is huge, it's better to define it once in source file, and declare it with extern
in the header.
Upvotes: 6