Assignment to restricted pointer

If you have a simple question and just want an answer.
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Assignment to restricted pointer

Post by DemoniacMilk »

Heyo!

I have an array of pointers within a struct. The struct saves the client state for one of multiple clients for an interface.

Code: Select all

sscPacket_t *packet[SSC_CLIENT_PACKETS_FIFO_SIZE];  // Buffer for incoming SSC Packets
the pointer is meant to point to a packet I received over a serial synchronous bus that is stored in an array of packets. On trying to assign the pointer to the client

Code: Select all

clientState->packet[iWrite] = pPacket;
with pPacket being of type sscpacket_t *

copmailing fails due to
assignment to restricted pointer
but I find something similar in the ethernet library. whats my mistake?
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Post by DemoniacMilk »

decalring the struct as a C struct removed the compiler complaints.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

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;
}