View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
structs memory usage |
Posted: Tue Jun 01, 2004 9:03 am |
|
|
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 |
Posted: Tue Jun 01, 2004 9:09 am |
|
|
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
|
|
Posted: Tue Jun 01, 2004 10:00 am |
|
|
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
|
|
Posted: Tue Jun 01, 2004 10:18 am |
|
|
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
|
|
Posted: Tue Jun 01, 2004 10:46 am |
|
|
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. |
|
|
|