there's like 10,0000,0 accounts with names like "Best Heritage Posts" and "Tumblr Hall Of Fame Posts" and "So Funny Hellsite Posts" but where's the shitty posts accounts. where's the hall of fail accounts. i want to see the worst of the worst
Given the following declaration and initialization:
auto x = 'a';
what is the type of x?
x is a char
x is a short
x is an int
x is a long
x is something else
this won't compile because auto isn't a C keyword
this won't compile for some other reason
(see results)
Remaining time: 4 days 13 hours
There are two correct answers here:
Under C99, C11, and C17 (GCC/Clang flags "-std=c99", "-std=c11", or "-std=c17"), the answer is "this won't compile for some other reason".
Under C89, C95, and C23 (GCC/Clang flags "-std=c89", "-std=iso9899:199409", and "-std=c23"), the answer is int.
Why? A few reasons:
auto is, in fact, a keyword. It has been since C89, and since K&R before that, and since B before that. It is a storage-class specifier (like static or thread_local or constexpr) and means "automatic storage duration"; AKA "this variable is freed at the end of the enclosing scope", AKA "this is a stack variable". Automatic storage is the default storage class for local variables (of course), and also only valid for local variables, so prior to C23 specifying it was always redundant.
Prior to C99, variable declarations without a type were implicitly given the type int.¹ Thus, in C89 and C95, this declaration is equivalent to auto int x = 'a';
From C99 until C23, this won't compile, but only because variable declarations without a type are illegal. auto is still a legal storage specifier. The relevant GCC/Clang diagnostic is -Wimplicit-int.
In C23 this declaration becomes legal once again, because a variable declared with the auto storage specifier and without a type (a so-called "direct declarator") now performs type inference. This is equivalent to writing auto typeof('a') x = 'a';
"But wait," you might ask, "why is x an int, if its type is inferred from its initializer? Isn't 'a' a char?" Nope! That's the case in C++, but confusingly, character literals in C have the type int, and thus so does x. We would have to write auto x = (char)'a'; to declare x to be a char.
¹A remnant of this behavior persists: writing unsigned, signed, short, long, or long long is equivalent to writing unsigned int, signed int, short int, long int, or long long int.
try and tell me literally any one of these would not fit above a short story about two wholly random men from the MCU fingering each other, or possibly 12 chapters of one or more characters from a CW show being in high school while having a photogenic but terminal kind of cancer. try.