You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing an external C function with an aggregate return type to be used in a PLC program, our API-guideline requires the return type to be passed as a pointer as the first parameter. This, however, is not very intuitive and might easily be missed.
If that is the case, the remaining input parameters are simply written over the memory location at which the return pointer would start, resulting in corrupted data.
and then running the compiled object with LD_LIBRARY_PATH=./a.out
the printf statement in the C function will print an empty line (in this case, this might differ depending on input parameters).
This can lead to very frustrating errors to debug, since it is not immediately apparent where one might have made a mistake.
For external functions with aggregate returns, we should additionally add a hint, pointing the user in the right direction in case they use a C library.
The text was updated successfully, but these errors were encountered:
mhasel
changed the title
Validate parameter count/types for external functions
Add a hint for external functions with aggregate return types
Oct 30, 2024
When writing an external C function with an aggregate return type to be used in a PLC program, our API-guideline requires the return type to be passed as a pointer as the first parameter. This, however, is not very intuitive and might easily be missed.
If that is the case, the remaining input parameters are simply written over the memory location at which the return pointer would start, resulting in corrupted data.
To reproduce:
ffi.c
:header.st
:ffi_used_in_plc.st
:After compiling with
and then running the compiled object with
LD_LIBRARY_PATH=./a.out
the
printf
statement in the C function will print an empty line (in this case, this might differ depending on input parameters).This can lead to very frustrating errors to debug, since it is not immediately apparent where one might have made a mistake.
For external functions with aggregate returns, we should additionally add a hint, pointing the user in the right direction in case they use a C library.
The text was updated successfully, but these errors were encountered: