Facing problem with bit fields, when i am compiling my code with GCC.

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

 



Hello,

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...,
union
{
   unsigned_8 indicator;
   struct
   {
   unsigned_8 unused : 6;
   unsigned_8 speed   :1;
   unsigned_8 time    :1;
   }bit;
}msg;

In code, speed and time bits are set as follows

msg.bit.speed=TRUE;
msg.bit.time=TRUE;

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

Thanks....
 Mulakkayala


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux