Comment by tialaramex
3 years ago
Sure, I don't seriously expect C to embrace that, even though I think it'd be worth the effort I'm sure plenty of their users don't.
For auto I think the argument is that if you poke around in real software the storage specifier was basically never used because it's redundant. That's the rationale WG21 had to abolish its earlier meaning in C++ before adding type deducing auto.
As I read it, N2368 (which I think is what they took?) gives C something more similar to the type inference found in many languages today (which gives you a diagnostic if it can't infer a unique type from available information) whereas C++ got deduction which will choose a type when ambiguous, increasing the chance that a maintenance programmer misunderstands the type of the auto variable.
However it got inference from return, which I think is a misfeature (although I think I can see why they took it, to make generics nicer). With inference from return, to figure out what foo(bar)'s type is, I need to read the implementation of foo because I have to find out what the return statements look like. It's more common today to decide we should know from the function's signature.
This is somewhat mitigated by the fact that N2368 says auto won't work in extern context, so we can't just blithely say "This object file totally has a function which returns something and you should figure out what type that is" because that's clearly nonsense. You will have the source code with the return statements in it.
We took N3007 which does not have inference on return etc. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm
Ah, great. I don't write very much C any more, but the auto described in N3007 (well, the skim of N3007 I just did) feels very much like what I'd want from this feature in C and perhaps more importantly, what I'd assume auto does if I see it in a snippet of somebody else's code I'm trying to understand.
Or how to make everyone life worse for the few weirdos that don't use a LSP/IDE. The type of auto on the return of a function can and is automatically shown e.g. https://resources.jetbrains.com/help/img/rider/2022.1/inlay_... With this kind of non-consideration of the developer comfort, it is clear C is an obscolete language.
C++ got auto because C++11 introduced types that could not be named, and this had to be inferred using auto.