In the code review process, one of my coworkers mentioned to me that \"const\"s in front of \"primitive types\" used as a function parameter in a header is meaningless, and
I thought that const
is a hint for the compiler that some expressions don't change and to optimize accordingly. For example I was testing if a number is prime by looking for divisors up to the square root of the number and I thought that declaring the argument const
would take the sqrt(n)
outside of the for
loop, but it didn't.
It may not be necessary in the header, but then again, you could say that all you need is to not modify the argument and it is never necessary. I'd rather see const
where it is const, not just in the source, but in the header too. Inconsistencies between declaration and definition make me circumspect. Just my opinion.