3 ms·
You're right, I also mark array definitions as const to control the section they go in, I was thinking about things like const int a = 5; ... anything I want a
by outsomnia 3y ago
You're right, I also mark array definitions as const to control the section they go in, I was thinking about things like const int a = 5; ... anything I want a simple const var for is done with #define for me.
const is indeed viral when eg, used in apis, but it's a strong indication at a glance for api users what they can expect to happen to the memory the pointer points to, whether it's just for input or is modified... and the virality is only a pain (it can be a pain) if you didn't use it from the start so all the things it might call are already kitted out with it.
- jstimpfle 3y agoconst makes sense and rarely causes problems when used in function parameter lists. However, when used for members in datastructures, it's more often than not problematic.