2 ms·
Of course that should be const uint32_t conf = read1(mgr->regs + OFF_MACHINE_ID); and the 'mgr' argument should be const:ed, too. :) That makes it much mo
by unwind 8y ago
Of course that should be
const uint32_t conf = read1(mgr->regs + OFF_MACHINE_ID);
and the 'mgr' argument should be const:ed, too. :) That makes it much more clear that this kind helper is just reading something out, and not poking stuff around. Always const all the things.
Have you even bothered checking if your compiler inlines this? It sure looks like a very likely candidate.
- simias 8y agoI agree that the pointer to mgr should've been const, that's a mistake on my part. On the other hand "const"ing the local integer is a bit overkill IMO (I do think that languages like Rust are right to default to const, but doing the same thing in C adds a lot of noise IMO).
- cmroanirgo 8y agoFrom the article (and follows my experience): "Const parameters and const functions are helpful in avoiding side effect related bugs, but the functions are still susceptible to changes in the global execution environment. Trying to make more parameters and functions const is a good exercise, and often ends in casting it away in frustration at some point. That frustration is usually due to finding all sorts of places that state could be modified that weren't immediately obvious -- places for bugs to breed. "