News for hackers. Stuff that matters.
Re:My favourite C++ footgun by towergratis on Tuesday June 22, 2021 @05:13PM (#27597296)
The real problem is not specific to C++, memory or shared pointers, but as the author mentions later, the fact that "function parameters evaluation order is unspecified".

The problem is similar in C as well.

`printf("%d, %d", i++, i++);` will give you different results depending on the compiler.

Re:My favourite C++ footgun by Koshkin on Tuesday June 22, 2021 @05:22PM (#27597399)
The situation is even worse, due to the possible interleaving of the execution of function calls.
Re:My favourite C++ footgun by towergratis on Tuesday June 22, 2021 @05:29PM (#27597474)
The root cause is the same
Re:My favourite C++ footgun by jhgb on Wednesday June 23, 2021 @06:36PM (#27611429)
How is it "the same"? If the evaluations of the individual arguments can't overlap, then the C example's problem still exists while the C++ example's problem doesn't. And if the order of evaluation were guaranteed but the evaluations could overlap, the C example wouldn't have a problem but the C++ example still would. To me the two problem's causes seem quite different.
Re:My favourite C++ footgun by Koshkin on Tuesday June 22, 2021 @05:40PM (#27597574)
Well, except that C does not have exceptions (at least not in the way that C++ does).
Re:My favourite C++ footgun by gpderetta on Wednesday June 23, 2021 @07:22AM (#27603178)
longjmp for the win (or loss)!
Re:My favourite C++ footgun by pjmlp on Wednesday June 23, 2021 @03:39AM (#27601854)
Right, it has signals and almost no one ever bothers to test for EINTR.