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 Wed, Jul 15, 2009 at 09:04:44AM +0100, Matthias Scheler wrote:
 > > Looks fine to me.

actually with static __inline you probably also want __unused.

 > How will it work out with compilers != GCC?

inline is part of C99.

It's probable that we ought to put something like

   #if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)
   /* gcc's non-C99 inline semantics */
   #define __INLINE extern inline
   #elif defined(__STDC__) && __STDC_VERSION__ >= 199901L
   /* C99 */
   #define __INLINE inline
   #else
   /* something else; static inline is safest */
   #define __INLINE static inline
   #endif

into cdefs.h and use __INLINE on inline functions, both here and other
places in libc. However, that's more or less a separate issue. The
existing inline functions in sys/endian.h are static __inline.

 > > Except, hmm, maybe the inline functions should be called something
 > > like __noswap{16,32,64} so they can be shared.
 > 
 > I'm not sure I understand what you mean.

as in

static __inline uint32_t __unused
__noswap32(uint32_t u)
{
        return u;
}

   :

#define ntohl(x) __noswap32(x)
#define htonl(x) __noswap32(x)
#define htobe32(x) __noswap32(x)
#define be32toh(x) __noswap32(x)


Also, I note that this:

#define htole16(x)      bswap16((uint16_t)(x))
#define htole32(x)      bswap32((uint32_t)(x))
#define htole64(x)      bswap64((uint64_t)(x))

and the various similar cases should probably lose the casts, and I
guess we'd also better audit all the MD definitions.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index