Is there any practical difference between the following prototypes?
void f(const int *p);
void f(const int *restrict p);
void f(const int *volatile p);
The section C11 6.7.6.3/15 (final sentence) says that top-level qualifiers are not considered for the purposes of determining type compatibility, i.e. it is permitted for the function definition to have different top-level qualifiers on its parameters than the prototype declaration had.
However (unlike C++) it does not say that they are ignored completely. In the case of const
this is clearly moot; however in the case of volatile
and restrict
maybe there could be a difference.
Example:
void f(const int *restrict p);
int main()
{
int a = 42;
const int *p = &a;
f(p);
return a;
}
Does the presence of restrict
in the prototype allow the compiler to optimize out the read of a
for return a;
?