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 CCS Technical Support

Union and structure?

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







Union and structure?
PostPosted: Thu Jul 22, 2004 9:15 am     Reply with quote

Could some one told me how to nested the structure into Union
And could some one give out some samples to me?


union { congiguration for shift register
char ShiftReg;
struct {
unsigned char ShiftRegLSB :1; // less significant bit'
unsigned char s1:1;
unsigned char s2:1;
unsigned char s3:1;
unsigned char s4:1;
unsigned char s5:1;
unsigned char s6:1;
unsigned char ShiftRegMSB :1; //most significant bit
} ;
};


i write the program like this, but the CCS compiler can not recoginize the
the structure of shiftreg

please give me some hint:)
Ttelmah
Guest







Re: Union and structure?
PostPosted: Thu Jul 22, 2004 10:26 am     Reply with quote

garyzheng217 wrote:
Could some one told me how to nested the structure into Union
And could some one give out some samples to me?


union { congiguration for shift register
char ShiftReg;
struct {
unsigned char ShiftRegLSB :1; // less significant bit'
unsigned char s1:1;
unsigned char s2:1;
unsigned char s3:1;
unsigned char s4:1;
unsigned char s5:1;
unsigned char s6:1;
unsigned char ShiftRegMSB :1; //most significant bit
} ;
};


i write the program like this, but the CCS compiler can not recoginize the
the structure of shiftreg

please give me some hint:)

You don't declare a varable name for the structure definition (only inside). So how is it going to be referred to in the structure?. This won't work in other C's either.
Use something like:
struct bits {
int8 LSB:1;
int8 s1:1;
int8 s2:1;
int8 s3:1;
int8 s4:1;
int8 s5:1;
int8 s6:1;
int8 MSB:1;
};

union {
char ShiftReg;
struct bits bitaccess;
} value;

Then value.ShiftReg, is the whole register, while value.bitaccess.LSB, refers to the LSB.

Best Wishes
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

Re: Union and structure?
PostPosted: Thu Jul 22, 2004 10:49 am     Reply with quote

Ttelmah wrote:
garyzheng217 wrote:
Could some one told me how to nested the structure into Union
And could some one give out some samples to me?


union { congiguration for shift register
char ShiftReg;
struct {
unsigned char ShiftRegLSB :1; // less significant bit'
unsigned char s1:1;
unsigned char s2:1;
unsigned char s3:1;
unsigned char s4:1;
unsigned char s5:1;
unsigned char s6:1;
unsigned char ShiftRegMSB :1; //most significant bit
} ;
};


i write the program like this, but the CCS compiler can not recoginize the
the structure of shiftreg

please give me some hint:)

You don't declare a varable name for the structure definition (only inside). So how is it going to be referred to in the structure?. This won't work in other C's either.
Use something like:
struct bits {
int8 LSB:1;
int8 s1:1;
int8 s2:1;
int8 s3:1;
int8 s4:1;
int8 s5:1;
int8 s6:1;
int8 MSB:1;
};

union {
char ShiftReg;
struct bits bitaccess;
} value;

Then value.ShiftReg, is the whole register, while value.bitaccess.LSB, refers to the LSB.

Best Wishes


thank you very much:) i got your point:)
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