|
|
View previous topic :: View next topic |
Author |
Message |
NathanI Guest
|
Using a union inside a struct |
Posted: Fri Feb 16, 2007 1:30 pm |
|
|
Hi, I did a forum search, but didn't find anything that matched my question. Basically I want to do this:
typedef union _CALDATA
{
unsigned int16 word;
signed int16 sword;
struct
{
byte L;
byte H;
} BYTES;
} CALDATA;
typedef struct
{
CALDATA minVal;
CALDATA maxVal;
CALDATA curVal;
} MINMAXCAL;
This compiles fine, but when I reference it by doing this:
myVarArray[5].minVal.word = 0x0000;
Compiler says
*** Error 57 "**Location**" Line 753(37,43): Expecting a structure/union
Please let my know if this is possible, thanks in advance.
P.S. I am using compiler version 3.184 and I replace my directory with **Location**. |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 16, 2007 4:12 pm |
|
|
I don't see any actual declaration of 'MyVarArray'.
It compiles fine on 3.163, 1nd 3.191 (the two nearest versions I have to 3.184), with:
Code: |
// First declare the data type
typedef union {
unsigned int16 word;
signed int16 sword;
struct {
byte L;
byte H;
} BYTES;
} CALDATA;
//Now a structure of these types
typedef struct {
CALDATA minVal;
CALDATA maxVal;
CALDATA curVal;
} MINMAXCAL;
//Now declare the array
MINMAXCAL MyVarArray[10];
void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
//Now access the array
MyVarArray[5].minVal.word=0x0L;
}
|
This correctly uses 60 bytes, and the list shows the correct 16bit word being accessed.
Best Wishes |
|
|
Guest
|
|
Posted: Fri Feb 16, 2007 5:14 pm |
|
|
Wow, yeah sorry for wasting your time. I had declared it not as an array. Forgot to adjust my temp variable. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|