Skip to content

Bug: returning arrays from functions generates hilariously bad C code #41

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

Open
alastairreid opened this issue Feb 21, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@alastairreid
Copy link

Two issues

  1. The function prototype is "T F32" which is the type of an array of functions that return T.
  2. The value is returned by "return result;" where result is an array. This just returns the address of the array.

The fix is probably to do the same that we do for FFI functions: pass in a pointer to where the result should go

    void F(T result[32]) {...}

An alternative might be to adapt the tuple return code to put the array in a struct the same way that we do if the return type is a tuple.

    struct F_result { T r0[32]; };
    struct F_result F() {...}

The second might be easier.

@alastairreid alastairreid added the bug Something isn't working label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant