3 ms·
'auto' is a terrible choice of the keyword. 'var', like in C#, would be much, much better. But no, the C/C++ people have been bitten by this weird keyword overl
by Koshkin 9y ago
'auto' is a terrible choice of the keyword. 'var', like in C#, would be much, much better. But no, the C/C++ people have been bitten by this weird keyword overload bug - the same one that caused 'static' to also mean "local"...
- nightcracker 9y agoThe issue is that 'var' would make old code not compile anymore, while 'auto' was already a keyword with pretty much no use.
- monocasa 9y agoExactly; 'auto' was the corollary of 'register'. Ie. it specified that the variable was to be put into automatic storage. On most architectures this means the stack. So not only did it specify what was the default behavior anyway, but it's better to let the compiler figure that out too.
- Koshkin 9y agoThe change of the meaning of 'auto' already broke the old code. In C, 'auto' is used to specify a storage class; in C++, it stands for the type. So, the valid C code auto float x; when compiled with a C++ compiler, produces an error message.
- beojan 9y agoIf we're talking about actual C++ code, auto is a reserved keyword (so it wouldn't be used as an identifier) but it was useless, so it wouldn't be used as a keyword in any real (C++) code.
- TheCoelacanth 9y agoThat was virtually never used in the wild, though.
- rootbear 9y agoThe real problem here is that keywords are in the same namespace as identifiers. If keywords were marked syntactically in some way and in their own namespace, there would be less reason to avoid introducing new ones. This is why we end up with _Bool, _Atomic, _Complex, etc., with hacky macro aliases. This is a problem in nearly all programming languages I'm familiar with.
- gumby 9y ago> 'auto' is a terrible choice of the keyword. 'var', like in C#, would be much, much better. I don't know; "auto" to me means "automatically deduced". While "var" sounds like it should apply only to variables, and auto to types (including return types, argument types etc). The reality is it could have been called "floog" -- after a while I don't even think of the English meaning of "if" when I write "if (foo)...", much less "for(...", and non-english speakers simply learn the keywords by rote, much as non-Italian speakers learn western musical notation by rote (or do you silently translate "fortissimo" in your head as you play?)
- mwkaufma 9y ago#define var auto
- Koshkin 9y agoThat's a slippery slope.