tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Fixing lint warnings

> Consider the following:
>       byte[0] = foo;
>       byte[1] = foo >>= 8;
>       byte[2] = foo >>= 8;
>       byte[3] = foo >> 8;
> which quite unambiguously convers a value to little-endian bytes.  It
> doesn't need any casts, nor any explict '& 0xff';

This is true only for 8-bit bytes.  We don't have anything else at
present, but (a) not all code is NetBSD-only and (b) I keep hearing of
efforts to create NetBSD/pdp10, which I would expect to have 9-bit which case you'd need to either (a) s/8/9/ (or perhaps
better s/8/CHAR_BIT/) if you want to convert to bytes or add &0xff if
you want to covert to octets.  (Unless, I suppose, you want octets and
whatever will be using byte[] doesn't care about bits above 0x80.)  And
it wouldn't surprise me if char went 16-bit even on todayish hardware
within the moderately foreseeable future.

Of course, there's also the issue of assuming that foo's value can be
stored in no more than four (bytes|octets), but that's separate.

Such future-proofing isn't worth doing in all cases.  But it should at
least get a little thought, I think.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index