Writing the actual addresses of a struct in memory???
-
Let me see if I can explain this with shortness and clearity. I am having to hard code the layout of a struct in memory. Meaning that I have to hard code the actual memory location of each element in the struct. Lets just say for simplicity that I have to start my first element at 0x0000. The struct is layed out like this:
struct data { double min[4]; double max[4]; char name[4]; int count; }
In order to create the struct in memory I think I need to create the layout of a byte(short word) like so:typedef union u_do_word{ unsigned short word; struct do_word_bits{ unsigned pad : 8; unsigned bit7 :1; unsigned bit6 :1; unsigned bit5 :1; unsigned bit4 :1; unsigned bit3 :1; unsigned bit2 :1; unsigned bit1 :1; unsigned bit0 :1; }bits; } do_word_t;
And create the pointer and variables for the elements I put the hex address in the name. start of the min arraystatic do_word_t word_0x00; static unsigned short *vme_word_0x00; //1st double in the min array static do_word_t word_0x20; static unsigned short *vme_word_0x20; //2nd double in the min array static do_word_t word_0x40; static unsigned short *vme_word_0x40; //3rd double in the min array static do_word_t word_0x80; static unsigned short *vme_word_0x80; //4th double in the min array
start of the max arraystatic do_word_t word_0xA0; static unsigned short *vme_word_0xA0; //1st double in the max array static do_word_t word_0xC0; static unsigned short *vme_word_0xC0; //2nd double in the max array static do_word_t word_0xE0; static unsigned short *vme_word_0xE0; //3rd double in the max array static do_word_t word_0x100; static unsigned short *vme_word_100; //4th double in the max array
start of the char array This is the part that I am not sure about. I believe that an unsigned short will give me the correct size for a double, but how should I do the char array. Is this correct???static do_word_t word_0x120; static unsigned char *vme_word_0x120; //1st char in the name array static do_word_t word_0x**?????**; (?? 0x124 ??) static unsigned char *vme_word_0x?**????**; //2nd char in the name array static do_word_t word_0x**?????**; (?? 0x128 ??) static unsigned char *vme_word_0x**?????**; //3rd char in the name array static do_word_t word_0x**?????**; (?? 0x12C ??)
-
Let me see if I can explain this with shortness and clearity. I am having to hard code the layout of a struct in memory. Meaning that I have to hard code the actual memory location of each element in the struct. Lets just say for simplicity that I have to start my first element at 0x0000. The struct is layed out like this:
struct data { double min[4]; double max[4]; char name[4]; int count; }
In order to create the struct in memory I think I need to create the layout of a byte(short word) like so:typedef union u_do_word{ unsigned short word; struct do_word_bits{ unsigned pad : 8; unsigned bit7 :1; unsigned bit6 :1; unsigned bit5 :1; unsigned bit4 :1; unsigned bit3 :1; unsigned bit2 :1; unsigned bit1 :1; unsigned bit0 :1; }bits; } do_word_t;
And create the pointer and variables for the elements I put the hex address in the name. start of the min arraystatic do_word_t word_0x00; static unsigned short *vme_word_0x00; //1st double in the min array static do_word_t word_0x20; static unsigned short *vme_word_0x20; //2nd double in the min array static do_word_t word_0x40; static unsigned short *vme_word_0x40; //3rd double in the min array static do_word_t word_0x80; static unsigned short *vme_word_0x80; //4th double in the min array
start of the max arraystatic do_word_t word_0xA0; static unsigned short *vme_word_0xA0; //1st double in the max array static do_word_t word_0xC0; static unsigned short *vme_word_0xC0; //2nd double in the max array static do_word_t word_0xE0; static unsigned short *vme_word_0xE0; //3rd double in the max array static do_word_t word_0x100; static unsigned short *vme_word_100; //4th double in the max array
start of the char array This is the part that I am not sure about. I believe that an unsigned short will give me the correct size for a double, but how should I do the char array. Is this correct???static do_word_t word_0x120; static unsigned char *vme_word_0x120; //1st char in the name array static do_word_t word_0x**?????**; (?? 0x124 ??) static unsigned char *vme_word_0x?**????**; //2nd char in the name array static do_word_t word_0x**?????**; (?? 0x128 ??) static unsigned char *vme_word_0x**?????**; //3rd char in the name array static do_word_t word_0x**?????**; (?? 0x12C ??)
The size of a double is 8 bytes. Use the sizeof(double) to see that your self. I have no clue why you would want to do this. Also if you don't pack the data using #pragma pack(push,1) before your struct and #pragma pack(pop) after your struct you will get unexpected results. John