Bug in sysdeps/generic/bits/byteswap.h

Scott Bambrough scottb@corelcomputer.com
Fri Nov 20 13:25:00 GMT 1998


This is from sysdeps/generic/bits/byteswap.h

/* Swap bytes in 32 bit value.  */
#ifdef __GNUC__
# define __bswap_32(x) \
    (__extension__                                                            \
     ({ unsigned int __bsx = (x);                                             \
        ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >>  8) |    \
         (((__bsx) & 0x0000ff00) <<  8) | (((__bsx) & 0x000000ff) << 24)); }))
#else
static __inline unsigned int
__bswap32 (unsigned int x)
{
  return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >>  8) |
          (((__bsx) & 0x0000ff00) <<  8) | (((__bsx) & 0x000000ff) << 24));
}
#endif

If __GNUC__ is not defined, this will fail to compile.  Need to change __bsx to
x or rename the parameter to __bsx.  Also, while we are looking at this, I'm
curious why glibc defines __bswap_32 if __GNUC__ and __bswap32 if not?  The same
is done for the 16 bit version.  This code is from the 2.0.102 snapshot I
downloaded from alpha.gnu.org.


Scott



More information about the Libc-hacker mailing list