both of these functions are (under my compiler at least) guaranteed to create a seg fault, yet i have no idea why. i really like their functionality and i have seen similar examples, so i am curious to know what is going wrong here or how to do what i think this actually does, which is passing a “level” into some function and then being able to manipulate its variable (eg lvl.lvl_cl[x][y][z] = some_number) and then pass it back for further use
any help is appreciated 🙂
typedef struct {
int lvl_cl[500][500][50];
char lvl_ch[500][500][50];
} level;
level plugh(level * in_lvl){
in_lvl->lvl_cl[444][444][44]++; //it segfaults even if this line is removed
return * in_lvl;
}
level foo(level inlvl){
inlvl.lvl_cl[443][443][43]++; //it segfaults even if this line is removed
return inlvl;
}
int main(void){
level world;
plugh(&world);
foo(world);
return 0;
}
Every time you call
foofunction it copies the wholeworldstructure and it is quite big. Try to pass the pointer: