cvs commit: src/sys/sys endian.h src/share/man/man9 byteorder.9

Ruslan Ermilov ru at FreeBSD.org
Fri Apr 4 23:34:56 PST 2003


On Sat, Apr 05, 2003 at 04:55:26PM +1000, Bruce Evans wrote:
> On Fri, 4 Apr 2003, Nate Lawson wrote:
> 
> > On Fri, 4 Apr 2003, Ruslan Ermilov wrote:
> > > +#define	BSWAP16(x)	(uint16_t) \
> > > +	(((x) >> 8) | ((x) << 8))
> > > +
> > > +#define	BSWAP32(x)	(uint32_t) \
> > > +	(((x) >> 24) | (((x) >> 8) & 0xff00) | \
> > > +	(((x) << 8) & 0xff0000) | ((x) << 24))
> 
> > I don't mind the addition of the macros but I don't like the
> > implementation.  Too many unnecessary casts and overly complicated.
> 
> I fear it has not enough necessary casts :-).  E.g., if x = (int16_t)0xfffe,
> then on 32-bit machines sign extension gives 0xffffffff for BSWAP16(x).
> Of course, BSWAP16()'s arg should be precisely uint16_t,

Yes, this is assumed.

> but the function
> interfaces don't require it to have the correct type except possibly on
> non-2's complement machines where coercing the arg's type may cause
> surprising changes to the arg's value.
> 
> Bruce

-- 
Ruslan Ermilov		Sysadmin and DBA,
ru at sunbay.com		Sunbay Software AG,
ru at FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/cvs-all/attachments/20030405/0b6e9f6a/attachment.bin


More information about the cvs-all mailing list