WEXITSTATUS(stat_val) is a macro (so in fact it does not “return” something, but “evaluates” to something).
For how it works you might like to look it up in the headers (which should be #included via
The implementation of this macro might differ from one C-implementation to the other.
Please note, that this macro only gives a sane value, if the macro WIFEXITED(stat_val) gave you a value unequal to 0.
Verbatim from waitpid()’s POSIX specification:
WEXITSTATUS(stat_val)
If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main().
The motivation behind adding up the return code(s?) of a particular program is only known to the code’s author and the hopefully existing documentation.