   Pointer to an array of pointers
  hello, i'm trying to create a pointer that points at an array of pointers, the code i'll post is only a simple example of my implementation, so please don't worry if it doesn't make sense why i'd be doing it like i am:#include<stdio.h>void TestOut(float x, float y, float Width, float Height){   float z=0.0f;   float Pnts[] = {x,y,z, x+Width, y,z, x+Width,y+Height,z, x,y+Height, z};   float *Ind[] = {Pnts, Pnts+3, Pnts+6,Pnts+9};   float *D = (float*)Ind;   for(int i=0;i<4;i++){ for(int d=0;d<3;d++) printf("%f ",D[d+i*3]); printf("\n");   }}int main(int argc, char **argv){   TestOut(0,0,100,100);   return 0;}/*Output:0.000000 0.000000 0.0000000.000000 0.000000 0.0000000.000000 0.000000 0.0000000.000000 0.000000 0.000000*/i believe the problem has to do with D = (float*)Ind is equal to D = Ind[0]; so when i get to D[3], it's looking at invalid data, but i'm really not sure   
Quote:i believe the problem has to do with D = (float*)Ind is equal to D = Ind[0];No, D = (float*)Ind[0]; is equal to D = Ind[0];... What D = (float*)Ind does is take a float** and pretend it's a float*, which is wrong.This is why C-style casts are bad - you're performing an invalid cast.If it doesn't compile without the cast in there, then putting a cast in there doesn't fix it, it just stops the compiler from being able to tell you it's wrong.Try:void TestOut(float x, float y, float Width, float Height){  float z=0.0f;  float Pnts[] = {x,y,z, x+Width, y,z, x+Width,y+Height,z, x,y+Height, z};  float *Ind[] = {Pnts, Pnts+3, Pnts+6,Pnts+9};  float **D = Ind;  for(int i=0;i<4;i++){    for(int d=0;d<3;d++)    { float* p = D[d+i*3]; float f  = *p; printf("%f ",f);    }    printf("\n");  }}Ind and D both point to an array of pointers.[EDIT]This code should crash if you run it though... there's 4 items in Ind/D, but you're trying to read 12 items out of it.The inner loop should probably look like  for(int i=0;i<4;i++){    float* p = D;    for(int d=0;d<3;d++){ float f  = p[d]; printf("%f ",f);    }    printf("\n");  };  no no, what ur doing means their's no reason for me to create the pointer D, what i want is such that D points to what Ind does, but as single valuesi.e:D[0] = Ind[0][0] = Pnts[0];D[1] = Ind[0][1] = Pnts[1];D[2] = Ind[0][2] = Pnts[2];D[3] = Ind[1][0] = Pnts[3];...;  Can you explain your motive a little bit? This all seems very bizarre.Is what you want a 12 element array D that contains the same 12 values that are in Ind[][]? Ignoring the point that in this case you just want (float *D = Pnts)...Ind is an array of pointers. These could be pointers to any address in memory.Ind[0] = 0x00010000Ind[1] = 0x12300000Ind[2] = 0x0fff8000Ind[3] = 0xbeefbeefYou can't just magically cast this and make all of the values appear in 12 contiguous memory locations. If you really want to build D, then you have to iterate through all the elements of Ind and copy them.   ;  i was afraid that'd be my only solutionD is just the result of me trying to verify the sceGumDrawArray function on the psp, the last param is a list of vertices, however, it's faster to have a direct list of vertices than an indiced list of vertices, so i thought of a way to do an array of pointers to my vertices, however as u've just expressed, when trying to submit this array of pointers which contains all my vertices in the order i need, i lose my pointer list in the processi don't want to have to copy each vertice into the list of face's, since it'd be much easier to manipulate 1 vertice, which would manipulate all the face's verticeshowever, as discussed that may not be possible   ;Quote:Original post by slicer4everno no, what ur doing means their's no reason for me to create the pointer DI just fixed your broken code. What is your reason for creating D?Quote:what i want is such that D points to what Ind does, but as single valuesi.e:D[0] = Ind[0][0] = Pnts[0];...Outside of just writing float *D = Pnts; (which satisfies your test case), what you're asking for can't be done through simple pointer assignment.Are you asking for D to be a new array which decodes the array Ind into a linear array of floats? If so, you can't expect a cast to figgure that out for you... you'll have to do that yourself, like:float D[12];for(int i=0;i<4;i++)  for(int d=0;d<3;d++)    D[d+i*3] = Ind[d];for(int i=0;i<4;i++){  for(int d=0;d<3;d++){    float f = D[d+i*3];    printf("%f ",f);  }  printf("\n");};  posted just as i posted my reasoning, thanks for the help guys, i was hoping when i implemented my animation code, that the only way to do it would be to re-build the faces each new animation sequence   ;  so, um, after talking to someone.. void func(int x, int y, int w, int h){   int a[]={x,y,x+w,y,x+w,y+h,x,y+h};   int *b[] = {a,a+2,a+4,a+6};   int *c = *b;   for(int i=0;i<4;i++){ for(int d=0;d<2;d++) printf("%d ",c[d+i*2]); printf("\n");   }   return;}int main(int argc, char **argv){   func(0,0,100,100);   return 0;}results:http://codepad.org/4T3PVaizthanks guys=-)   ;Quote:Original post by slicer4everno no, what ur doing means their's no reason for me to create the pointer D, what i want is such that D points to what Ind does, but as single valuesi.e:D[0] = Ind[0][0] = Pnts[0];D[1] = Ind[0][1] = Pnts[1];D[2] = Ind[0][2] = Pnts[2];D[3] = Ind[1][0] = Pnts[3];...if this is the case could you just not do something like this?float Pnts[12] = {x,y,z, x+Width, y,z, x+Width,y+Height,z, x,y+Height, z};float Ind[4][3];&Ind = Pnts;for( int i = 0; i < 4; i++){    printf("%f %f %f\n", Ind[0], Ind[1], Ind[2] );};  my sample code is confusing i admit, because what i'm essentially doing is pointing back at Pnts exactly as it's layed out, but that's because it's just that sample code, and now i have a working method to implement itbut here's a more in-depth thought of why i plan to do it, basically, 8 pnts to represent a cube, 12 triangles to create a filled cube, now then, rather than duplicating all the points for each triangle, i can create it my vertices directly, and if i want to move a point, then instead of updating all the pnts in the faces list, i simply change the vertice, and the faces update automaticallythat's a more sensible reason of why i'm doing this   