Hacker News new | ask | show | jobs
by sdk77 982 days ago
The case of what is a constant, and whether or not it even really is, is not always clear in C. As an embedded developer (almost always on bare metal), variables declared with the const modifier are usually (but not always, it depends on the linker script) placed in read only memory. For those kind of variables (read only ones, they're not really constants as in C++ constexpr) I don't use all caps. But for preprocessor macros, always. Even "#define MY_CONSTANT 10" is a macro, and not a constant or a variable. And it should be treated with caution, because it is dangerous (inexperienced programmers might change it to #define MY_CONST 2 * OTHER_CONSTANT, which opens up a can of worms).