Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong behavior on returning mutli field structs #63

Open
amiremohamadi opened this issue Dec 2, 2024 · 0 comments
Open

fix: wrong behavior on returning mutli field structs #63

amiremohamadi opened this issue Dec 2, 2024 · 0 comments

Comments

@amiremohamadi
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant