3 ms·
The last time I worked meaningfully with C++ was back in 2013. Now that I write mostly Rust and TypeScript, I'm amazed by how C++ has changed over the years! R
by tigranbs 10mo ago
The last time I worked meaningfully with C++ was back in 2013. Now that I write mostly Rust and TypeScript, I'm amazed by how C++ has changed over the years!
Regarding the "auto" in C++, and technically in any language, it seems conceptually wrong. The ONLY use-case I can imagine is when the type name is long, and you don't want to type it manually, or the abstractions went beyond your control, which again I don't think is a scalable approach.
- tialaramex 10mo agoType inference is actually very useful you just need to have the right amount, too little and most of your time is spent on bureaucracy, too much and the software is incomprehensible. In both Rust and C++ we need this because we have unnameable types, so if their type can't be inferred (in C++ deduced) we can't use these types at all. In both languages all the lambdas are unnameable and in Rust all the functions are too (C++ doesn't have a type for functions themselves only for function pointers and we can name a function pointer type in either language)
- 1718627440 10mo ago> C++ doesn't have a type for functions themselves only for function pointers C has this, so I think C++ has as well. You can use a typedef'ed function to declare a function, not just for the function pointer.
- gpderetta 10mo agoSame in C++. You can't do much with the function type itself as there are no objects with that type, but you can create references and pointers to it.
- 1718627440 10mo agoBut typedef void * (type) (void * args); type foo; a = foo (b); works?
- meindnoch 10mo agoThose are function pointers. Your parent was referring to the function type. Per ISO/IEC 9899:TC3: A function type describes a function with specified return type. A function type is characterized by its return type and the number and types of its parameters. A function type is said to be derived from its return type, and if its return type is T , the function type is sometimes called ‘‘function returning T’’. The construction of a function type from a return type is called ‘‘function type derivation’’.
- 1718627440 10mo agoNot necessarily, foo can also just be an ordinary function. That was my point. > Per ISO/IEC 9899:TC3: What is it supposed to tell me?
- tialaramex 10mo agoISO/IEC 9899 is the name of the ISO document describing the C programming language. The current edition is, I think the 2023 document aka C23. You can read a "draft" of that document here: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf [If you've ever been under the impression that "real" people use the actual ISO text, disabuse yourself of that notion, ISO takes ages to turn the same exact words into an official branded document, then charges $$$ for a PDF, ain't nobody got time or money for that] I can't tell you what they intended by TC3. It might be a typo or it might be some way to refer to a specific draft or a section within that draft. I doubt this particular section changes frequently so I wouldn't worry about it.
- 1718627440 10mo agoThanks, I did know that. My question was what kind of claim that quote is supposed to support, not where the quote is from.
- gpderetta 10mo agoTechnical Corrigendum 3. It was an amendment to the '99 standard that contains a few important clarifications.
- 0xcafecafe 10mo agoAnother place where auto can be useful is to handle cases where the function signature changes without making changes at the calling site. An explicitly typed var would need changing or worse, can work with some potential hidden bugs due to implicit type conversion.
- 1718627440 10mo agoThis is one of the things static typing is supposed to prevent in the first place. It seems like a lot of people actually want a dynamically typed language, but try to change a static language instead.