I want to change the structure of a code from array of structs to struct of arrays. So I changed this part (arrays are declared dynamically) :
To this:Code:float *velxl, *velyl,*childl; int inc = some_value; int i; velxl = (float *)&childl[0*inc]; velyl = (float *)&childl[1*inc];
I know the last two lines are wrong, ( I think nbodiesl should be defined as an array of pointers to the struct instead of an array of structs ) but I don't know how to do it in C.Code:struct body { float velxd, velyd;}; body *nbodiesl; for(i=0;i<something;i++){ nbodiesl[i].velxd = (float *)&childl[0*inc+i]; nbodiesl[i].velyd = (float *)&childl[1*inc+i]; }
I appreciate if you could come up with an alternative solution, too.
Thanks



LinkBack URL
About LinkBacks



