glibc documentation and endianness glibc documentation and endianness unix unix

glibc documentation and endianness


This is not an endianness issue. Endianness refers to how the data is stored in memory; on either a big- or little-endian machine, (((status) & 0xff00) >> 8) extracts bits 15 through 8, i.e. the 8th through 15th least significant bits of the status macro argument.

The documentation and comments are confusing because status refers to two different things.

The process that exits returns a status code. This exit status has type int in the source (either as return value from main, or as argument to exit), however, the value should be between 0 and 255.

The wait and waitpid system calls also provide a status back to the caller. This status is different; the low-order 8 bits of the original exit status are now in bits 15 through 8. I assume the documentation says WEXITSTATUS returns the "low-order 8 bits" because that was the packing of the exit status from the perspective of the exiting process.