tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: type behavior of sys/endian.h

On Sun, Jul 12, 2009 at 04:54:11PM +0000, David Holland wrote:
> 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.

No, because that would hide broken argument passing.

> Or maybe they should be made inline functions instead so they don't
> fail silently if passed pointers.

That would be better but I think we should use inline function *and*
defines. There might be some broken programs out there which use
"#ifdef ntohl" which will be true under NetBSD, Solaris and Linux at
the moment.

So what about this?

static __inline uint32_t
__ntohl_inline_dummy(uint32_t x)
        return x;
#define ntohl(x)        __ntohl_inline_dummy(x)

        Kind regards

Matthias Scheler                        

Home | Main Index | Thread Index | Old Index