C
Comp1597
Is the following code legal?
void f(const int ing)
{
ing++;
}
int main()
{
}
I would have thought not, and my compiler agrees. It's an error
because a const is being modified.
However, on another thread someone commented on passing a const
parameter by value instead of using a pointer to const or a reference.
In relation to this practice, the comment was
" the function's implementation is
free to omit the const qualifiers regardless of whether they are
included in this prototype. "
So is it the case that my code would be legal on some compilers and
not others? If my code is always illegal, what does it mean to say
"the function's implementation is free to omit the const
qualifiers" ?
Thanks
void f(const int ing)
{
ing++;
}
int main()
{
}
I would have thought not, and my compiler agrees. It's an error
because a const is being modified.
However, on another thread someone commented on passing a const
parameter by value instead of using a pointer to const or a reference.
In relation to this practice, the comment was
" the function's implementation is
free to omit the const qualifiers regardless of whether they are
included in this prototype. "
So is it the case that my code would be legal on some compilers and
not others? If my code is always illegal, what does it mean to say
"the function's implementation is free to omit the const
qualifiers" ?
Thanks