But that code isn't portable for a different endian machine. To write portable endian clean code, you want to write functions/macros named like:
cpu_to_le32(),
cpu_to_be32(),
be32_to_cpu(),
le32_to_cpu(),
etc. (and similar for 16, and 64 bit quantities) similar to what's described here:
https://kernelnewbies.org/EndianIssues)
These functions will either swap, or not, depending on the endianness of the target machine, and this decision is made at compile time, so the "no swap" case imposes no performance penalty.)
That way, the intent is clear, and the code works on big endian and little endian. So instead of what you propose, which I imagine you might use via:
x = some_value; /* say this is big endian, and we want it little endian, because we're on Intel. */
uint32_t y = read_int((char *) &x);
you'd have:
y = be32_to_cpu(x);
Now the intent is clear, and the code is portable, x is big endian, and we want native CPU (whether that be big endian or little endian).
Likewise, you could write:
x = cpu_to_be32(y);
say before writing it out to disk or network for some purpose that requires big endian.
This is similar to htonl(), ntoh(), htons(), ntohs(). (host to network/network to host long/short).