Here, you’ll find all the posts I’ve collected about anime girls eating spaghetti. If you find a post about anime girls eating spaghetti on your adventures, don’t forget to bring it to me! Something nice might happen if you find them all…
this comic was originally meant to be a metaphor about my current depressive slump, but o was ironically too depressed to do more than 7 pages. i also didn't realize that it's kind of just Kafka's Metamorphosis but ✨for girls✨
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: 6 days 6 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.
[Image ID: Tumblr tags from haunted-skitty-doll reading: lemme guess you have mixed feelings on competitive cause you're not very good at it, i could get to the top of the abortion ladder ez /End ID]