What is the difference between:
const variable = 10;
and
const int variable = 10;
Does variable, per the standard, get interpreted as an integral type when no type is defined?
What is the difference between:
const variable = 10;
and
const int variable = 10;
Does variable, per the standard, get interpreted as an integral type when no type is defined?
const variable = 10
is not valid C++, while const int variable = 10;
is.
The only time (that I can think of) that const variable = 10
would be valid is if you had a type named variable
and you had a function with an unnamed parameter of that type, taking a default argument:
typedef int variable;
void foo(const variable = 10);
With no strict rules (K&R C etc. Edit : i.e. old C), int is the type by default. It certainly does not mean the variable has no type, and it does not have anything to do with const.
const variable = 10;
won't compile in almost all new moderns C++ compilers.
It means that x is implicitly declared an int. This is not allowed in C++, but in C and to maintain compatibility with C headers or pre-ISO C++ code, a lot of contemporary C++compilers still support this as an option.
My GCC 4.4 compiler here groks "const x=3;" when feed -fms-extensions on the command line (the manual says, that it turns on a couple of lamps which are required to understand MFC code)
UPDATE: I've checked it with VS-2005, you can have implicit int if you use
#pragma warning(disable:4430)