Re: Artifact bitfield full? Or can I use the high bits?



On Feb 18, 12:22 am, Doug Freyburger <dfrey...@xxxxxxxxx> wrote:
Justin Hiltscher <jus...@xxxxxxxxxxxxxxxxxx> wrote:
Doug Freyburger <dfrey...@xxxxxxxxx> wrote:

Here's my take on bit fields - Assume a long is 32 bits
then don't use the sign bits just out of convervatism.
That leaves 28 bits available. Any work on these bits
will break save files so just do it and consider the work
a reset. There are plenty of bits left available.

Er... 32 bits of unsigned int means 31 bits of signed int
and 1 bit for the sign. You're either negative, or you're
not.

Call me paranoid then - The rare times I use bit fields I
avoid the sign bit of each byte. Byte addressing machines
might view any one byte or any length of bytes ending at a
byte as a flexible sized integer and I like to avoid sign bits
out of paranioa.

I go one step further, and declare the type unsigned (and never
access it other than as the type it is declared). That way,
there are no sign bits to worry about.

Of course, most of the time I use bit fields, it is in order to
be compatible with some external format (TCP header, etc.). In
which case, I use the bits the format requires:-).

--
James Kanze (GABI Software) email:james.kanze@xxxxxxxxx
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
.



Relevant Pages

  • Re: CPtrList with CSocket
    ... This means you don't need to declare ... Generally, you should avoid the ancient and, frankly, poorly-done, classes like CPtrList, ... By using two iteration mechanisms, one of which is inherently unrelated to the structure ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: How to optimize for win ce developlemnet
    ... There's not really any way to avoid that type of thing. ... You might declare a ... > Thanks paul for your advice. ... >> globally optimizing your code, at the cost of many weeks or months, ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: MBF to IEEE (Beg. Q)
    ... I'm only trying to wrap my mind around what is going on with ... you use a Declare to avoid the typelib. ...
    (microsoft.public.vb.general.discussion)
  • Re: Insurers warn on car alterations .
    ... lifestyles to avoid these hassles and expenses. ... Probably since car insurance has existed. ... Similarly, I have just renewed some building insurance, which required me to declare any modifications that might affect the level of risk insured. ...
    (uk.transport)