Excuse me but how should that work?
auto foo = 45;
What should that be?
It's an int. We know this because the (C++) standard says how
literals acquire implicit types, because its important (mainly) for
function overloading.
"An integer literal is a sequence of digits that has no period or
exponent part. An integer literal may have a prefix that specifies its
base and a suffix that specifies its type. The type of an integer
literal depends on its form, value, and suffix. If it is decimal and
has no suffix, it has the first of these types in which its value can
be represented: int, long int;"
45U is an unsigned int.
char, short, int, long long, unsigned char, unsigned short, unsigned int
or unsigned long long?
ALL those types qualify actually. Even float and double qualify also.
But the C++ standard says which one counts. The C standard doesn't
because there's no where that it matters. If you want a floating
point literal, use a decimal point.
auto f = 45.; // That's a double
"A character literal is one or more characters enclosed in single
quotes, as in ’x’, optionally preceded by the letter L, as in L’x’.A
character literal that does not begin with L is an ordinary character
literal, also referred to as a narrow-character literal. An ordinary
character literal that contains a single c-char has type char..."
It's a char. Again C++ has these rules, and they're pretty much ass
you'd expect (if it looks like a char, its a char...)
In C++ with the template stuff it is maybe necessary, but in C???
I agree. With the present simple type system, . But some of the
suggestions made here for C improvement (namespaces, function
overloading) will complicate the type system to the extent that there
may be some gain. It really is easier to type:
auto it = container->first_element();
rather than
struct bobs_namespace::vector_of_float::iterator it = container-
and its makes it easier to change the type of container without
invalidating vast swathes of other code.