4 ms·
It's more useful in C++ with things like generic and voldemort types, but I still would not discount it in C as the lack of namespacing impacts type names, and
by masklinn 3y ago
It's more useful in C++ with things like generic and voldemort types, but I still would not discount it in C as the lack of namespacing impacts type names, and it could limit convenience typedefs (those which exist only to avoid the `struct` and `enum` prefixes). It might also help transitioning to fixed integer types, which are rather verbose.
- kevin_thibedeau 3y agoC has generics as well. This permits the return type of generic functions to be preserved.
- jcranmer 3y agoThe only generic feature C has is the _Generic expression, which isn't a function, but closer to a switch(typeof(x)) expression.
- kevin_thibedeau 3y ago_Generic can be used to merge a collection of functions.
- CyberDildonics 3y agoThat's not the same as being able to write a data structure that takes any type.
- kevin_thibedeau 3y agoIt's still generic. You don't have to have feature parity with C++ to meet that bar.
- CyberDildonics 3y agoThat would be like calling function overloading generics.
- neutrono 3y agoIt should have been called _Overload or something similar, since it's not really a generic.
- rightbyte 3y agoHah. Voldemort types. The ones that can't be named (in practice becouse too long to fit on a line or remember)?
- gpderetta 3y agoAlso because they might be a) an undocumented implementation detail (the result of std::bind for example); b) utterly unutterable like the type of a lambda expression.
- masklinn 3y ago> The ones that can't be named (in practice becouse too long to fit on a line or remember)? Nah those are easy to name, just annoying, it's types which literally don't have an external / public name, like lambdas, or locally defined types.
- bheadmaster 3y agoIt's actually a struct that only has a name in the scope of the function which returns `auto`, and thus cannot be named outside of it. Like this: #include <iostream> auto createVoldemortType(int value) { struct Voldemort { int value; }; return Voldemort{value}; } int main() { auto voldemort = createVoldemortType(7); std::cout << voldemort.value << std::endl; // output: 7 }
- krater23 3y agoThis way to code is a good reason to make auto the same tabu as goto.
- trealira 3y agoI wonder how much this complicates parsing C++. Because of this, you can't discard/free struct and class definitions as soon as you leave the scope, like you can in C, because the definition can still escape the scope by being returned from a function with the "auto" keyword.
- 3y ago