M
Even better, this changes on whether the function has been declared previously. Here is a sample that reproduces the problem in Visual 2005:
Header file:
//TestConstParam.hpp
#include < cstddef>
int Sum(int const *tab, std::size_t length);
Source file 1:
//TestConstParam1.cpp
#include <cstddef>
//#include "TestConstParam.hpp"
int Sum(int const * const tab, std::size_t const length)
{
int sum = 0;
for(std::size_t i=0; i<length ; i++) { sum += tab[i]; }
return sum;
}
Source file 2:
//TestConstParam2.cpp
#include "TestConstParam.hpp"
void TestConstParam(void)
{
int tab[] = {1, 2, 3};
int sum1 = Sum(tab, 3);
sum1++; //hides "unused" warning
}
This reproduces the problem in Visual 2005, but it disappears if you uncomment the #include line in TestConstParam1.cpp. When the function is pre-declared with non-const parameters, this actually changes the mangled name under which the function definition is exported (from ?Sum@@YAHQEBH_K@Z to ?Sum@@YAHPEBH_K@Z)