|
|
View previous topic :: View next topic |
Author |
Message |
d00dajo
Joined: 20 Jul 2004 Posts: 34
|
Defining a structure in CCS, linearly |
Posted: Fri May 13, 2005 5:05 am |
|
|
Hi,
I have run into a problem with code explosion using the CCS compiler.
Now, what I want to define is something like:
struct
{
int8 b[6]
int8 c[8]
int8 d[2]
int 8 e
}a[3]
That is , I want to access a[1].d[0] etc. Now, looking at the assembler code generated I suspect that the structure is NOT saved in the way I intended it to be.
The way I want to be able to use it, the memory for "b" should be allocated linearly.
That is, to get a[1].b[5] I would like to use
int16 * ptr ;
ptr = a[1].b;
ptr[5]; //THIS SHOULD BE a[1].b[5]
Now, it appears that the struct is not saved in this manner. How do I define a structure with the memorymapping I want?
That is memory usage as follows (in bytes):
//Start of struct
adr+0:[a0.b0]
adr+1:[a0.b1]
adr+2:[a0.b2]
adr+3:[a0.b3]
adr+4:[a0.b4]
adr+5:[a0.b5]
adr+6:[a0.c0]
....
And so on.
(Yes, I could manually define every variable and separate them, but surely there must be a way to define a struct to do this?)
Thanks in advance //DJ. |
|
|
Guest
|
Re: Defining a structure in CCS, linearly |
Posted: Fri May 13, 2005 6:02 am |
|
|
In the portion of code you write, ptr is defined as a pointer to int16, so ptr[5] will return the value of the 5th int16 located 10 bytes after a[1].b.
So,
//THIS SHOULD BE a[1].b[5] : NO
Now, it appears that the struct is not saved in this manner: are you sure ? How is it stored then ?
In my apps, I never had the strange behaviour you are describing (I have arrays of structs each composed of others struct (these containing bit fields) and arrays of int8) |
|
|
JPA Guest
|
Re: Defining a structure in CCS, linearly |
Posted: Fri May 13, 2005 6:03 am |
|
|
In the portion of code you write, ptr is defined as a pointer to int16, so ptr[5] will return the value of the 5th int16 located 10 bytes after a[1].b.
So,
//THIS SHOULD BE a[1].b[5] : NO
Now, it appears that the struct is not saved in this manner: are you sure ? How is it stored then ?
In my apps, I never had the strange behaviour you are describing (I have arrays of structs each composed of others struct (these containing bit fields) and arrays of int8) |
|
|
d00dajo
Joined: 20 Jul 2004 Posts: 34
|
OF COURSE!!!!!!!!!!!!!!!!! |
Posted: Fri May 13, 2005 6:30 am |
|
|
Hi,
Of course you are right. I couldnt for my life figure out WHY the compiler would store the information in any other way than in a linear fashion. And of course, it doesnt. It works exactly as I wanted it to, the error was in accessing the struct.
Thanks for your help!
//DJ. |
|
|
d00dajo
Joined: 20 Jul 2004 Posts: 34
|
OF COURSE!!!!!!!!!!!!!!!!! |
Posted: Fri May 13, 2005 6:30 am |
|
|
Hi,
Of course you are right. I couldnt for my life figure out WHY the compiler would store the information in any other way than in a linear fashion. And of course, it doesnt. It works exactly as I wanted it to, the error was in accessing the struct.
Thanks for your help!
//DJ. |
|
|
|
|
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
|