Date: Sat, 5 Apr 2003 16:55:26 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: Nate Lawson <nate@root.org> Cc: Mike Barcroft <mike@FreeBSD.org> Subject: Re: cvs commit: src/sys/sys endian.h src/share/man/man9 byteorder.9 Message-ID: <20030405164849.Y37179@gamplex.bde.org> In-Reply-To: <Pine.BSF.4.21.0304041150530.17052-100000@root.org> References: <Pine.BSF.4.21.0304041150530.17052-100000@root.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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, 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030405164849.Y37179>