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

Defining a structure in CCS

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



Joined: 20 Jul 2004
Posts: 34

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

Defining a structure in CCS
PostPosted: Fri May 13, 2005 5:02 am     Reply with quote

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.
Konrad



Joined: 15 Sep 2003
Posts: 34

View user's profile Send private message

pointerss to structures
PostPosted: Wed Jun 01, 2005 5:03 pm     Reply with quote

I assume that this was a quick post, but your syntax is no quite right-

struct a *ptr ; //declare a pointer to a structure
ptr = &a[1];

theVar = ptr->b[5]; //access variable

int16 * ptr ; //declares a pointer to an int16 i.e. 2 bytes
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