Re: C array pointers
- Posted by begin Jul 11, 2018
- 1843 views
following feed running 64bit phix: sequence poly = {100,100,200,300,100,150,200,100,400,100,200,300,380,150,100,100
goes into function:
public procedure drawpoly(sequence polypointegers) integer len = 0, j=0 ifdef BITS32 then len = 4 elsedef len = 8 end ifdef integer plen = length(polypointegers) atom poly = allocate(len*plen, true) for i=1 to plen do ifdef BITS32 then poke4(poly+j, polypointegers[i]) elsedef poke8(poly+j, polypointegers[i]) end ifdef j += len end for c_proc(_drawpoly,{plen, poly}) end procedure
c function recieves compiled 64bit:
void bgi_drawpoly(int numpoints, const int *polypoints) { CHECK_GRAPHCS_INITED FILE *x = fopen("test.txt", "wx"); POINT *points = (POINT *) malloc(numpoints * sizeof(POINT)); for(int i = 0; i < numpoints/2; i++) { points[i].x = *(polypoints++); points[i].y = *(polypoints++); fprintf(x, "points[i].x %d points[i].y %d\n",points[i].x, points[i].y); } fclose(x); BEGIN_DRAW Polyline(activeDC, points, numpoints/2); END_DRAW free(points); }
points[i].x 100 points[i].y 0 points[i].x 100 points[i].y 0 points[i].x 200 points[i].y 0 points[i].x 300 points[i].y 0 points[i].x 100 points[i].y 0 points[i].x 150 points[i].y 0 points[i].x 200 points[i].y 0 points[i].x 100 points[i].y 0
what do i do wrong?? 32 bit is no problem
richard
ps soccer - what a bummer