I got bit big time on this one. The GCC compiler recognizes only int for a
bit field base. This is, of course, 2 bytes in the 16-bit compiler and 4
bytes for the 32-bit compiler. The legacy code I was porting had a bunch of
"unsigned short" bitfields for that very reason and nuked big time under
Linux. My personal opinion is that GCC should support the various sizes
considering the lack of control over the size of 'int.' My opinion
notwithstanding, the "standard" says it's up to the implementation so, there
ya go.

Thus, if you *really* want to be portable, I'd suggest declaring these
fields as "unsigned short", etc. and do the bit-masking yourself. It's the
only way to be sure to get consistent results. It might work now but you can
bet it will rear it's ugly head and bite your *** in the future.

Ciao,
Dee

P.S. It's likely my Win32 coding days are numbered. I'm seriously
considering accepting an offer for $300/wk more than my present salary and
it's exclusively a Linux shop. What can I say? Double the vacation, less
hours, more money, less stress and ... I'll get to smoke at my desk instead
of outside in the cold. Tempting, huh?


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Palmer, Jean L.
Sent: Monday, March 22, 2004 10:40 AM
To: [EMAIL PROTECTED]
Subject: [msvc] using bit fields


I am making an updated version of an application that uses bit fields.  For
instance, there are variables of type
unsigned int max : 10
unsigned int rng : 3
unsigned int sec : 8

These values will be written to a binary file, which must be able to be read
in by another existing application.  So, for instance, there must only be 3
bits written to file for variable 'Rng', or the other application won't read
the data in correctly.  This can't be changed.

First, should I change the values which are of size 8 bits to small ints,
and forget using bit fields for those?  Can I depend on a small int to be 8
bits, 20 years from now?

Second, what is the best way of dealing with the other variables which are
bit fields (different than 8 bits), in cases such as assignment? Should I
make a typedef for each different bit size, then use a static_cast?

Jean Palmer
> * [EMAIL PROTECTED]
>
>

_______________________________________________
msvc mailing list
[EMAIL PROTECTED]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for
subscription changes, and list archive.



Reply via email to