I see in a lot of legacy software and bad tutorials on the Internet that recommend using
return -1 or similar to represent "abnormal termination". The problem is, in POSIX at least,
-1 has never been and is not a valid status code.
man 3 exit illustrates that
exit() returns the value of
status & 0377 to the parent, meaning that
255. On non-POSIX systems,
EXIT_FAILURE is recommended for portability. But I never see "-1 means abnormal termination" in conjunction with "EXIT_FAILURE may be something other than 1", indicating that they clearly believe "-1" is conventional even on non-POSIX systems.
Here's an example of a StackOverflow question that perpetuates this. The software "unrealircd" is also an example of a program that uses
exit(-1) to terminate the program. In practice, this makes it difficult to interface with
Where did this anti-pattern come from? Is it valid in some context?