CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Using a union inside a struct

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
NathanI
Guest







Using a union inside a struct
PostPosted: Fri Feb 16, 2007 1:30 pm     Reply with quote

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







PostPosted: Fri Feb 16, 2007 4:12 pm     Reply with quote

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








PostPosted: Fri Feb 16, 2007 5:14 pm     Reply with quote

Wow, yeah sorry for wasting your time. I had declared it not as an array. Forgot to adjust my temp variable.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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