Facing problem with bit fields, when compiling with GCC.

Devendra Mulakkayala dmulakkayala@indusrad.com
Wed Apr 5 09:58:00 GMT 2006


ISSUE: Facing problem with bit fields, when i am compiling my code with
GCC. It was previously compiled with diab compiler and was working fine.

In our code Union definition is as follows...,
   unsigned_8 indicator;
   unsigned_8 unused : 6;
   unsigned_8 speed   :1;
   unsigned_8 time    :1;

In code, speed and time bits are set as follows


Some where in code there is check for indicator as follows

if(indicator==03) /* this is to check whether speed and time bits are set.
If yes go iside block */

unused 6 bits are initialized to 0.

This code previously compiled with diab compiler and working fine. Now i am
trying to compile with GCC compiler.

The problem here is
1. If speed and time bits are set, these bits are coming in MSB. That is it
is coming 1100 0000 ( C0 ) instead of 0000 0011 (03 ). That why eventhough
speed and time bits are set, condition is not satisfying because indicator
value is 'C0' not '03'.
2. Compiler is assigning the memory from bottom to top for bit fields in
the structure. Previously in diab compiler it is aligning bits from top to
bottom, with that our code was working fine.
2. I know that these bit fields are compiler dependent. Is there any option
in GCC to set the bit fields from top to bottom ( MSB to LSB )
in structure.
3. As per the client requirement we are not supposed to change the code. I
am looking for any option or any other way to solve this problem.

Please help me in this


Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/

More information about the Cygwin-xfree mailing list