Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
David Prentice
09/11/12 05:39
Read: 700 times

#188308 - Just use C expression
Responding to: Maarten Brock's previous message
Maarten Brock said:

C-standard said:
The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined.

This means that the compiler gets to choose which order it uses (globally, not case-by-case) and another compiler can make a different choice.

It is never wise to rely on bitfield allocation strategy.

final_var => D7 D6 D5 D4 D3 var3.D6 var2.D4 var1.D7

final_var = (var4 & 0xF8) | ((var3 & 0x40) >> 4) | ((var2 & 0x10) >> 3) | ((var1 & 0x80) >> 7);


Of course you could map any bit to wherever you want.

The >> operator takes quite a lot of cycles. Different C expressions may be compiled more efficiently. In practice, it won't really matter.


List of 11 messages in thread
Different variable bit merge into single variable?      Yagnesh Mehta      09/10/12 04:48      
   Of course      Per Westermark      09/10/12 05:02      
      its bit addressable....      Yagnesh Mehta      09/10/12 05:38      
         No      Per Westermark      09/10/12 06:39      
            just want to check...      Yagnesh Mehta      09/10/12 22:16      
               What was missing in the answers you have already received?      Per Westermark      09/11/12 00:21      
                  no defined bit order      Maarten Brock      09/11/12 03:26      
                     Just use C expression      David Prentice      09/11/12 05:39      
         what is wrong with IE?      Erik Malund      09/10/12 07:01      
            Right!!!!!!!!!!      Yagnesh Mehta      09/13/12 00:29      
               gobbledygook      David Prentice      09/13/12 05:09      

Back to Subject List