Something's wrong with us if this has to be mentioned in a list like this.
Something's wrong with us if this has to be mentioned in a list like this.
If you want to convince a single other person that a C program you have written has no undefined behavior, then you and that person have to hopefully interpret English the same way. It would be completely hopeless to try to convince a hundred people that a nontrivial C program has no undefined behavior. And successful programs typically have way more than a hundred users.
static void takes_null_reference_by_default(int& p = *((int*) nullptr)) {
if (&p) ++p;
}
int main(int argc, char* argv[]) {
int v1 = 15;
int v2 = 25;
takes_null_reference_by_default(v1);
takes_null_reference_by_default();
takes_null_reference_by_default(*((int*) nullptr));
takes_null_reference_by_default(v2);
std::cout << v1 << " " << v2 << std::endl;
}
Now g++ complains with: junk.cpp:5:10: warning: reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true
[-Wundefined-bool-conversion]./a.out still runs though. And the de-references are just pseudo-de-references, it never "really" happens.
EDIT: also mentioning the fits "delete this;" gave some people, but worked very well in the ACE Networking Library and various other places.
And COM is future of Win32, rebranded as UWP.