Facing problem with bit fields, when compiling with GCC.

Larry Hall (Cygwin X) reply-to-list-only-lh-x@cygwin.com
Thu Apr 6 00:55:00 GMT 2006


Devendra Mulakkayala wrote:
> 
> 
>  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


This isn't a Cygwin-X issue.  If this is a Cygwin issue, ask it on the main
list.  But before you do that, you should make sure that it is a Cygwin issue
and not a gcc one.  If it is the latter, then you want to ask about this on
the gcc list instead.


-- 
Larry Hall                              http://www.rfk.com
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
838 Washington Street                   (508) 893-9889 - FAX
Holliston, MA 01746

--
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