[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Structure, bit-fields, optimization...
From: |
Andrej Krpic |
Subject: |
[avr-gcc-list] Structure, bit-fields, optimization... |
Date: |
Tue, 25 Jun 2002 17:12:03 +0200 |
Hello,
I have come to the problem, which I do not know how to solve.
If I define a structure
typedef structure MyStructTAG {
uint8_t ID;
uint8_t Status:1;
uint8_t Value:7;
uint8_t ModeBit1:1
utin8_t Value2:7;
uint8_t ModeBit2:1
utin8_t Value3:7;
} MyStruct, *MyStructPnt;
declare it,
MyStruct tmpStruct;
try to read it from eeprom:
One Way:
register uint8_t Temp;
Temp = eeprom_rb(address);
tmpStruct.ID = Temp;
Temp = eeprom_rb(address+1):
tmpStruct.Value = Temp&0x7F;
tmpStruct.Status = Temp&0x80;
Temp = eeprom_rb(address+2)
tmpStruct.Value2= Temp&0x7F;
tmpStruct.ModeBit1 = Temp&0x80;
.... and so on...
I think there has to be more efficient way... like:
*(&tmpStruct.ID + offset) = eeprom_rb(address + offset);
0<=offset<4
But the second method doesn't work. Any help is appreciated.
Also, I would like to know, "how" to program to make code smaller, tips &
tricks are very
welcome.
Thanks,
Andrej
avr-gcc-list at http://avr1.org
- [avr-gcc-list] Structure, bit-fields, optimization...,
Andrej Krpic <=