Size-independent byte order swapping functions.

Pawel Jakub Dawidek pjd at FreeBSD.org
Tue Feb 3 02:36:26 PST 2004


On Tue, Feb 03, 2004 at 11:01:55AM +0100, Poul-Henning Kamp wrote:
+> >I'm planning to commit this patch:
+> >
+> >	http://garage.freebsd.pl/patches/endian.h.patch
+> 
+> I have a hard time seeing a sensible use for these.
+> 
+> Endianess conversion is almost exclusively used in communications
+> (even if the "transmission media" is a disk), and I can't possibly
+> see how it can make sense to be lax about wordsize but strict about
+> byteordering.
+> 
+> Could you please tell us what you need these for and why you could
+> not use the explicitly sized families of endian functions ?

I found them very useful while doing many such translations.
It protect from problems when you need to manage many such transformations.

For example, you have some structure:

struct mystruct {
	uint16_t	ms_foo;
	uint32_t	ms_bar;
	uint64_t	ms_foobar;
};

and many places where you translate those fields.
Suddenly, you need to change size of one of those fields.
If you were using size-independent functions you don't need to change
anything else, in other case diff will be much bigger with much
mistake probability.

Of course if only I found them useful, I'll stop right here.

-- 
Pawel Jakub Dawidek                       http://www.FreeBSD.org
pjd at FreeBSD.org                           http://garage.freebsd.pl
FreeBSD committer                         Am I Evil? Yes, I Am!
-------------- 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/freebsd-arch/attachments/20040203/a91ff65c/attachment-0001.bin


More information about the freebsd-arch mailing list