Skip to content

fix: wrong behavior on returning mutli field structs #63

@amiremohamadi

Description

@amiremohamadi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions