Ttelmah Guest
|
|
Posted: Sun Sep 03, 2006 6:37 am |
|
|
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 |
|