[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
type behavior of sys/endian.h
It came up recently (see source-changes-d) that ntohl and friends on
big-endian machines do not have the same type behavior as on
uint32_t ntohl(uint32_t) __attribute__((__const__));
uint32_t bswap32(uint32_t) __attribute__((__const__));
and one of
#define ntohl(x) bswap32((uint32_t)(x))
#define ntohl(x) (x)
If you do ntohl() on a signed value, whether the result is signed or
not is thus machine-dependent, and that seems like a bad idea.
So it seems to me that the BE definition of ntohl ought to be
#define ntohl(x) ((uint32_t)(x))
and similarly for all the other various nops in sys/endian.h.
Or maybe they should be made inline functions instead so they don't
fail silently if passed pointers.
David A. Holland
Main Index |
Thread Index |