AnsweredAssumed Answered

HCS08 C: bit field optimization

Question asked by Mehmet Fide on Feb 26, 2008
Latest reply on Feb 26, 2008 by Mehmet Fide
Hi,
 
I defined LCD segments as bits in a struct.
 
Code:
typedef struct{ unsigned char R0:1; unsigned char R1:1; unsigned char R2:1; unsigned char R3:1; unsigned char R4:1; unsigned char R5:1; unsigned char R6:1; unsigned char R7:1;} TBits;typedef union { unsigned char Val; TBits Bit;} TLcdByte;
#pragma DATA_SEG MY_ZEROPAGE
  TLcdByte LCD_RAM[20];

 
and the definitions:
Code:
#define IND_L1           LCD_RAM[10].Bit.R0#define IND_L2           LCD_RAM[14].Bit.R2#define IND_L3           LCD_RAM[14].Bit.R3#define IND_NL1           LCD_RAM[10].Bit.R2#define IND_NL2           LCD_RAM[14].Bit.R0#define IND_NL3           LCD_RAM[14].Bit.R1#define IND_T1           LCD_RAM[14].Bit.R5#define IND_T2           LCD_RAM[14].Bit.R7#define IND_T3           LCD_RAM[9].Bit.R4#define IND_T4           LCD_RAM[8].Bit.R4
...

 
If I use
Code:
 IND_NL1 = 0; IND_NL2 = 0; IND_NL3 = 0; IND_L1 = 0; IND_L2 = 0; IND_L3 = 0; IND_PP = 0; IND_NP = 0; IND_PQ = 0; IND_NQ = 0;

 

instead of

Code:
IND_NL1 = IND_NL2 = IND_NL3 = IND_L1 = IND_L2 = IND_L3 = IND_PP = IND_NP = IND_PQ = IND_NQ = 0;

it generates more optimal code. Is this normal?

CW v6.1

10x
 


 

Outcomes