I have a C structure (not C ++) that looks like this
typedef struct mystruct{ float a,b; int x, y; } mystruct;
Then in the function, I collect the data as follows:
mystruct List[MAX]; ListNumber = 0; for(i = 0; i < MAX; i++) { if(conditions_meet) { List[ListNumber].a = masterlist[i].a;
... etc.
ListNumber++; } }
then i send an array of function
DoStuff(static int max, mystruct array[max]){ Stuff }
It works, but when I try to do it like this ....
mystruct setter(int i) { mystruct TEMP; TEMP.a = masterlist[i].a; //......etc return TEMP; } mystruct List[MAX]; ListNumber = 0; for(i = 0; i < MAX; i++) { if(conditions_meet) { List[ListNumber] = setter(i); ListNumber++; } }
This causes a lot of funky bugs. Why is this happening? edit: @ tommieb75 I cannot give a lot of details, the results do not seem to have a template. The list is used as a generalized way to draw material on the screen, and the function, instead of directly setting it, makes odd problems with rendering and random order, but does not create compiler errors at all. gdb shows that integers are greater than an integer, which is the only pattern that I find. masterlist is a global array of a different structure. In this example, the data must be converted to a structure. No warnings or compiler errors at all. Perhaps I can include more sensitive warnings, but I am always informed of any common error that I can think of. I am going to try the chosen solution, which should be enough. In any case, similar functions that return structures are used in my code, and everything works fine, except in this case with an array of structures.
c arrays pointers
Balkania
source share