Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default type for C const?

Tags:

c

types

I was writing some C code, and noticed what I thought to be an error, but was not. I had the following type declaration statement.

const fee;

However, it was uncaught initially because the compiler and I didn't catch it. So I was curious as to why C allows this and what is the default type.

like image 723
jax Avatar asked Aug 06 '14 22:08

jax


1 Answers

Only the original version of C language standard (ANSI/ISO C89/90) allows this. Such variable declaration defaults to type int in accordance with "implicit int" rule. That rule was present in C since the beginning of time. That's just how the language was originally defined.

Note that the declaration-specifiers portion of a declaration cannot be omitted completely, e.g. a mere

fee;

does not declare an int variable. It is illegal even in the original C. But once you add some sort of declaration specifier or qualifier, the declaration becomes legal and defaults to int type, as in

static fee;
const fee;
register fee;

However, all this is illegal in C99 and in later versions of language, since these versions of language specification outlawed "implicit int".

like image 87
AnT Avatar answered Oct 13 '22 02:10

AnT