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

int16 within a STRUCT

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



Joined: 16 Sep 2005
Posts: 2
Location: Bothell, WA

View user's profile Send private message Send e-mail

int16 within a STRUCT
PostPosted: Mon Sep 19, 2005 6:10 pm     Reply with quote

I wanted to basically do something like:
Code:
struct {
    unsigned    preamble:8;
    unsigned    data:16;
    unsigned    crc:8;
}message;


but had to go with
Code:
struct {
    unsigned    preamble:8;
    unsigned    data_hi:8;
    unsigned    data_lo:8;
    unsigned    crc:8;
}message;

instead. Not really too much of a problem until I get to this part of the main program.
Code:

int16  data_temp;
#define TAG_ID_VALUE 0x6FC0
data_temp = TAG_ID_VALUE + id_counter;
//message.data_hi = MSB of data_temp
//message.data_lo = LSB of data_temp


I know about UNIONS and that I could create
Code:

union {
    int8 data[2];
    int16 data_temp;
} temp;

so that I could access the individual bytes within data_temp but I am at a loss as to how to combine the UNION and the STRUCT together.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 19, 2005 6:28 pm     Reply with quote

It should be like this:

Code:
struct {
    int8 preamble;
    int16 data;
    int8 crc;
}message;
Sonic Concepts



Joined: 16 Sep 2005
Posts: 2
Location: Bothell, WA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 19, 2005 6:37 pm     Reply with quote

Thanks, that worked. Just shows that I know enough to be dangerous but not enough to really know what I'm doing Embarassed
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