Do modern cars even allow you to step on the accelerator and the brake at the same time?
Retiring a favourite C++ joke
41–50 of 151 posts
Re: Retiring a favourite C++ joke
#42Re: Retiring a favourite C++ joke
#43Do modern cars even allow you to step on the accelerator and the brake at the same time?
Re: Retiring a favourite C++ joke
#44#include using namespace std; class BadProgrammer { public: void yep() { delete this; } }; int main() { auto x = BadProgrammer{}; x.yep(); cout g++ -Wall -Wextra -Wpedantic main.cc # compiles just fine clang++ -Wall -Wextra -Wpedantic main.cc # also compiles just fine
Re: Retiring a favourite C++ joke
#45Even the compilers are in on some jokes: $ gcc -xc - : In function ‘main’: :1:45: error: ‘long long long’ is too long for GCC
Re: Retiring a favourite C++ joke
#46I was surprised to see it not mentioned in the post -- the most obvious reason this joke should be retired is not the reference to a television show but rather the modern practice of never using new or delete at all in C++ code. Modern C++ avoids these pitfalls and I think it's been 10 years since I've written the words the new or delete.
Re: Retiring a favourite C++ joke
#47Maybe he can mock try next?
Don't mock try all the time
Re: Retiring a favourite C++ joke
#48#include using namespace std; class BadProgrammer { public: void yep() { delete this; } }; int main() { auto x = BadProgrammer{}; x.yep(); cout g++ -Wall -Wextra -Wpedantic main.cc # compiles just fine clang++ -Wall -Wextra -Wpedantic main.cc # also compiles just fine
So a conforming C++ compiler doesn’t have to diagnose this mistake, and similarly the compiled program doesn’t have to do anything meaningful either. For example, just ignoring the delete and printing the message is as valid a result as the more useful crash at the site of the bad operation.
Re: Retiring a favourite C++ joke
#49[flagged]
Re: Retiring a favourite C++ joke
#50i wouldn't say that's an illegal op per se, if anything it's a pretty safe op! tobias only ever existed in thought, not in body :( :(
maybe a compiler WARN or IGNORED_OP