On Thu Aug 17 15:23:11 2023 +0000, Alex Henrie wrote:
The main advantage is that a static constant can be initialized from a sizeof, which tells the reader that there is little chance that the magic number was calculated incorrectly. A static constant is also more likely to be optimized out, although in the case of a single integer it doesn't matter much.
Sorry, that was a poor explanation. A regular constant can also be initialized from a sizeof, so I could achieve the main goal of clarifying the code without changing the constant to be static.
Static constants do have another advantage besides optimization: They can be placed in read-only memory, so if someone editing this code did take a pointer to the constant and accidentally modify it, it would be obvious because the code would segfault. In my opinion that is a "nice to have" even though, like the optimization benefit, it doesn't matter very much in this particular case.