Hi DemoniacMilk,
By default, XC pointers are either 'restricted pointers' (global, params) or 'alias pointers' (local) depending where they are declared. If you want to change this, explicitly state them either restricted, alias, moveable or unsafe.
5.2.4.2 Restricted Pointers
In both C and xC there is the concept of a restricted pointer. This is a pointer that
cannot alias i.e. the only way to access that memory location is via that pointer. In
C, the compiler can assume that access via a restricted pointer is non-aliased but
does not perform any checks to make sure this is the case. In xC, extra checks
ensure that the non-aliasing restriction is true.
Here is an example of XC giving a compile time "assignment to restricted pointer" error:
Code: Select all
int *a1;
void foo(int* a2) {
a2 = a1;
}
void bar(void) {
foo(a1);
}
p.s. what you are doing with a pointer to an array of pointers to structs is fine - the following code compiles:
Code: Select all
typedef struct A {
int i;
} A;
typedef struct B {
A *a[10];
} B;
int foo(B *b, int x) {
return b->a[x]->i;
}