How can I make a pointer to a member of a struct, thats an array of ints. This is how the struct looks like:
typedef struct {
volatile int x[COORD_MAX];
volatile int y[COORD_MAX];
volatile int z[COORD_MAX];
//... other variables
} coords;
coords abc;
abc is a global variable.
Now, I would like to get pointers to x,y and z arrays and save them to another array. Then acces them through passing a wanted index. Here is what I mean:
void test(int index1, int index2)
{
static volatile const int* coords_ptr[3] = {abc.x, abc.y, abc.z};
coords_ptr[index1][index2] = 100;
}
So index1 would select which type of coordinates to choose from (x,y,z). And index2 would select which index of the coordinates to change.
Please note, that this is just a simplification of the code I am working on. But the principle is the same.
Thanks in advance!
EDIT:
I've written wrong code. Sorry for the confusion, this should be right now.
test, whatcoordsobject is the function operating on?coordsis a type, not an object.coords_ptr[index1][index2] = 100;:coords_ptr[index1][index2]isconst!