I was learning about const
type qualifier and I accidentally wrote the following code which I compiled with gcc -Wall -Wextra
:
#include <stdio.h>
int main(void)
{
const a = 5;
printf("%d\n", a);
return 0;
}
The compiler throws this warning:
warning: type defaults to ‘int’ in declaration of ‘a’ [-Wimplicit-int]
const a = 5;
^
The ouptut of the program is 5
. I tried to change const
with other type qualifiers like volatile
and _Atomic
and I have got the same result. I tried to use restrict
but I have got an error because I think this keyword is expecting a pointer.
My question is, is there any syntactic rule in the C standard, that requires from compilers to implicitly set to int the the type of a variable specified by a type qualifier without a specific type, or is it gcc specific extension?