4 ms·
In C++, "return (x);" isn't equivalent to "return x;" [0]. But according to OP, it's not C++ that's irrational, it's the programmers who don't want to use C++
by bumbledraven 9y ago
In C++, "return (x);" isn't equivalent to "return x;"
[0].
But according to OP, it's not C++ that's irrational, it's the programmers who don't want to use C++.
[0] https://twitter.com/sigfpe/status/857748171778252800 https://twitter.com/sigfpe/status/857748171778252800 [EDIT: corrected broken link]
- _pmf_ 9y agoThere's shooting yourself in the foot, and there's C++.
- stinos 9y agoOr one could say it's irrational to write return (x); :] More typing, less readable, more confusing.
- deleted 9y ago[deleted]
- simias 9y agoI'm not a big fan of the huge complexity of C++ (and much prefer C in general, although for some things C++ is more convenient) but I don't really think it's fair to dismiss a language based on a small snippet. You can basically mock any language that way: - In C "getchar" returns... an int. - Pointers and array are kinda the same thing, but not exactly. The rules for when an array decays into a pointer are sometimes unintuitive and surprising. - Same thing for the implicit integer types promotions. - `char *s = "foo"` is not at all the same thing as `char s[] = "foo"`. Arguably the former should be considered erroneous, but compiles just fine in C. G++ gives a warning for the same code however. - There's also the ridiculous "gets" function that's so poorly designed it could be part of PHP. This one finally got officially deprecated though. Of course many of these issues are also part of C++ since it's mostly a superset of C but in general it's stricter and more strongly typed.
- vostok 9y agoIntuitively, you can think of this as providing the name of a variable as compared to an lvalue that doesn't name a variable.
- machuidel 9y agoOh oh. Young me will get into trouble again: https://bytes.com/topic/c/answers/214712-using-return-parantheses https://bytes.com/topic/c/answers/214712-using-return-parant...
- sqeaky 9y agoYour link doesn't work for me. Can you perhaps just explain the difference? A twitter link is hardly a canonical source.
- Sean1708 9y agoThere are some trailing characters in the link. But the tweet is > decltype(auto) f1(){int x = 0; return x;} > decltype(auto) f2(){int x = 0; return (x);} > Latter, not former, returns reference to int.