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

pointer arrays

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



Joined: 02 Oct 2004
Posts: 22
Location: cleveland

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

pointer arrays
PostPosted: Sat Sep 02, 2006 6:15 am     Reply with quote

does CCS fully support arrays of pointers to structures.

Thanks
Ttelmah
Guest







PostPosted: Sun Sep 03, 2006 6:37 am     Reply with quote

Basically 'yes', but it depends what you mean by 'fully'. If data types and sizes get too complex, then sometimes 'fragility' can result. This is more because there is no memory management as such, so size/rule checking, is _completely_ down to you. Hence things that would raise an 'exception' when run on a PC, will be accepted, and result in problems, which can be a pig to track down. If you write carefully, and in a well structured manner, with 'tricks' to remind you of the data sizes involved, then even quite complex forms like unions inside structures, work fine. However _be careful_ when incrementing pointers. CCS sometimes increments pointers by one, rather than the sizeof the item addressed. It handles this with structures OK most of the time, but you should 'watch it' carefully.
So:
Code:

struct demo {
   int16 address;
   int8 array[4];
   int8 index;
} testval[2];

int pointer_test(struct demo * struct_ptr) {
   int8 rval;
   ++(struct_ptr->index);
   rval=struct_ptr->index;
   ++struct_ptr;
   rval+=struct_ptr->index;
   return rval;
}

If called with 'pointer_test(testval)', will correctly increment
testval[0].index, and add this to testval[1].index, returning the result. This correctly shows the pointer being incremented by 7 (the sizeof the structure).
However if you look at the CCS example files, and take d41256.c as a typical example, loking at the 'WordWrite' function, will show the example code being passed a pointer to a 16bit value, and incrementing it, to access the second byte, with the pointer being incremented by one. Incorrect. The pointer should need to be cast to address an 8bit value for this to work...
I have taken to explicitly casting pointers to 'int *', and then adding the 'sizeof' the item, if I am in any doubt.

Best Wishes
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