4 ms·
A small kitten dies every time C++ is used like its 1995. void (*fn)(void*, T) = nullptr;
by waynecochran 1y ago
A small kitten dies every time C++ is used like its 1995.
void (*fn)(void*, T) = nullptr;
- plq 1y agoUnless you mutter the magic incantation "C compatibility" while doing it
- waynecochran 1y agoAt this point, C++ has long abandoned C at the language level. If you are going to write C code, write C code -- don't hamstring modern C++.
- zabzonk 1y agodid nullptr exist in c++ back in 1995 - i can't remember
- trealira 1y agoNope, it was introduced in C++11, along with the type std::nullptr_t. Before that, you either used 0 or NULL, which was a macro constant defined to be 0.
- waynecochran 1y agoThat is the only thing "modern" in the above code and it does not save the kitten.
- tom_ 1y agoAnd another one dies every time you need to step through a call to std::function. Whatever you do, the kittens are never going to escape.
- waynecochran 1y agoTo save the kitten, one could at least write classes that override the call operator::(). No need for void* or any ptrs at all and std::function is avoided as well. That will at least get you to 2010 C++ code.