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

structs memory usage

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



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

structs memory usage
PostPosted: Tue Jun 01, 2004 9:03 am     Reply with quote

If I have a struct like this:

struct a {
int8 bytea;
int8 byteb;
int1 status1;
int1 status2;
int1 status3;
int1 status4;
int8 blnk:4;
} structure;

In memory will it be:

pointer--> 00000000 = bytea
00000000 = byteb
xxxxblnk = status 1,2,3,4 and blank

??
Ttelmah
Guest







Re: structs memory usage
PostPosted: Tue Jun 01, 2004 9:09 am     Reply with quote

future wrote:
If I have a struct like this:

struct a {
int8 bytea;
int8 byteb;
int1 status1;
int1 status2;
int1 status3;
int1 status4;
int8 blnk:4;
} structure;

In memory will it be:

pointer--> 00000000 = bytea
00000000 = byteb
xxxxblnk = status 1,2,3,4 and blank

??

It'll should be:
int8 bytea
int8 byteb
int8 _containing four seperate bits in use_ statusn
int8 blnk;

It will not 'split' integers across byte boundaries.

Best Wishes
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Tue Jun 01, 2004 10:00 am     Reply with quote

I want to give "names" to individual bits in a struct and I am not finding a way to do it.

The struct starts with some bytes and then have five bits that will be named.
Ttelmah
Guest







PostPosted: Tue Jun 01, 2004 10:18 am     Reply with quote

future wrote:
I want to give "names" to individual bits in a struct and I am not finding a way to do it.

The struct starts with some bytes and then have five bits that will be named.

Use this:
struct a {
int8 bytea;
int8 byteb;
int8 blnk:4;
int8 status1 : 1;
int8 status2 : 1;
int8 status3 : 1;
int8 status4 : 1;
} structure;

This describes 'status1..4', to be 'fields' in an int8 variable, each occupying just one bit.
This is the normal C way of doing it (int1, does not normally exist), and works. I thought you were trying to ask the order in which the bytes would be used to allow you to access them via a pointer.

Best Wishes
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Tue Jun 01, 2004 10:46 am     Reply with quote

I didnt explain very well in my post, but I was trying to create a struct, understand the format in ram and in what sequence it will access via pointer.

I´m thinking about:

union a {
int8 byte1;
struct b {
int8 bit0:1;
int8 bit1:1;
int8 bit2:1;
int8 bit3:1;
int8 bit4:1;
} bits;
};

struct c {
int8 byte1;
int8 byte2;
union a status; //it will be bit mapped and each bit has own name
} serialport;

This struct will be sent via serial port and interpreted by computer.
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