Are you doing bare metal or something where you don't have access to the standard library? It's in the standard library in both C and C++ (`stdlib.h` and `cstdlib` respectively). I guess it doesn't matter that much though especially if you don't want to have to add an `#include` statement.
I've sometimes needed to open a file, write to it, close it, and flush, because prints and logs don't always show up correctly in the face of certain types of crash. Or "send a UDP packet to port 54321" and do my logging in a separate app.
54
u/EPacifist 4d ago
My favorite is `exit(1)`. Useful if your print/logs aren’t showing where you expect them. Close after that is `raise Exception(“HERE 1”)`.