udem-dlteam / pnut

🥜 A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell
https://pnut.sh
BSD 2-Clause "Simplified" License
425 stars 14 forks source link

:barf array of struct and struct value type are not supported in shell backend. Use a reference type instead. #57

Closed Bilgus closed 4 months ago

Bilgus commented 4 months ago

/ Function computing the sum of an array / struct foo { int a; int b; }barf; int sum(int a, struct foo) { int i, sum = 0; for (i = 0; i < foo.a; i += 1) { b += a[i]; } return *b; }

:barf array of struct and struct value type are not supported in shell backend. Use a reference type instead.

maybe should mention that in your caveats too, whats a reference type?

laurenthuberdeau commented 4 months ago

The shell backend does not support using structs directly, either as a function parameter or as a local variable. This is documented in the Known Issues section of the README.

Aggregate types (arrays and structures) cannot be stack-allocated, passed by value or nested in a structure.

In your example, the sum function could take a pointer to a foo structure and it should work.