consider the following code:
void printf(char *, ...);
struct fields_t {
int a;
int b;
};
struct fields_t new_fields() {
struct fields_t f;
f.a = 13;
f.b = 69;
return f;
}
int main() {
struct fields_t f = new_fields();
printf("f.a: %d, f.b: %d\n", f.a, f.b);
return 0;
}
currently it leads to segmentation fault (which is probably related to this.
by fixing it, the segfault will be gone but still the value stored in f.b will be wrong (which is probably related to the way we store struct fields). the same thing works perfectly if we return a pointer to structs.