I have a C (not C++) struct that goes like this
typedef struct mystruct{
float a,b;
int x, y;
} mystruct;
Then in a function I collect data like this:
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 the array to a function
DoStuff(static int max, mystruct array[max]){
Stuff
}
This 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++;
}
}
It causes a lot of funky errors. Why is this happening? edit: @tommieb75 I can't give much detail, the results do not seem to have a pattern. The list is used as a generalized way to draw stuff to the screen, and having the function instead of the direct setting makes odd problems in rendering -and random-, but produce no compiler errors at all. gdb shows some integers as being larger than an integer, that's the only pattern I find. masterlist is a global array of another struct. The data needs to be converted to the struct in this example. No compiler warnings or errors at all. I can turn in more sensitive warnings maybe, but I always get reported of any general error I can think. I am going to try the selected solution, that should suffice. Anyway similar functions returning structs are used in my code and all work perfectly except for this case with an array of structs.