As far as why determining the endianness may be important, I often
write code to communicate among devices via SPI on devices where the
transmit buffer is 8 bits. Since I have to send data as a stream of
bytes, endianness becomes important.
In that case, do it yourself, so that you have control:
unsigned char message[SIZE];
... verify that "len" is in range, e.g., does not exceed 1023 ...
message[0] = FOO_CODE;
message[1] = (len >> 8) & 0xff; /* assumes len >= 0 */
message[2] = len & 0xff;
memcpy(&message[3], whatever, len);
send_SPI_data(..., message, len + 3);
This code works if your machine is little-endian, big-endian,
PDP-endian, or even My-Favorite-Martian-antenna-endian. It works
if your "char"s are 8 bits, or 9 bits, or 16 bits, or 32 bits
(provided send_SPI_data() can somehow manage to send the low 8 bits
of each "unsigned char" out to the appropriate device).
In short, it always works.