Const correctness
It is a programming principle that emphasizes the proper use of the const qualifier to enforce immutability . It involves applying the const keyword in a consistent and meaningful way to variables, function parameters, and pointers.
In C (and C++), the const keyword is used to declare that a variable is read-only and should not be modified. When applied to function parameters, it indicates that the function will not modify the passed arguments.
?
Const correctness brings several benefits to software development:
?
?
In summary: use a "constant" qualifier whenever the buffers are read only and not intended to be written. One common example is to passing data by address where the called routine is not allowed to change the data.
?
/*where bar pointed data is read only in scope of foo!*/
void foo(const uint32 * bar, uin8 size);
?