Add missing prototypes to user functions in sdlib.c - #23
Conversation
2fbb7ee to
8856809
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the SDFast code generator’s handling of user-supplied function pointers so generated C/C++ code uses proper function pointer prototypes (instead of deprecated/invalid “unspecified arguments” forms).
Changes:
- Add prototype strings for generated
VT_PROCNAMEparameters in root-finding and integrator helpers. - Extend the
packedvar_t/ var-decl machinery to carry and print function pointer prototypes for C-family languages. - Update
declare_proc/packvarcall sites to pass the prototype where needed.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| sdfast_main/sdroot.c | Adds a shared prototype string for root callback function pointers and passes it through packvar. |
| sdfast_main/sdinteg.c | Adds an integrator callback prototype string and uses it in declare_proc/packvar declarations. |
| calc/decl.c | Adds storage/varargs handling for VT_PROCNAME prototypes and prints C-family function pointers with explicit prototypes. |
| calc/calc.h | Extends packedvar_t with a pv_prototype field for procedure parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sherm1
left a comment
There was a problem hiding this comment.
@sherm1 reviewed 5 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on sherm1).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sherm1
left a comment
There was a problem hiding this comment.
@sherm1 reviewed 2 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on sherm1).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| vname = VARNAME(&*argptr, decl_flags, pvar); | ||
| char *prototype = NULL; | ||
| if ((vtype & VT_BASETYPE) == VT_PROCNAME) { | ||
| prototype = VARPROTOTYPE(&*argptr, decl_flags, pvar); | ||
| last_prototype = prototype; | ||
| } else if ((vtype & VT_BASETYPE) == VT_DUP && | ||
| (last_vtype & VT_BASETYPE) == VT_PROCNAME) { | ||
| prototype = last_prototype; | ||
| } |
There was a problem hiding this comment.
This introduces a declaration (char *prototype = NULL;) after an executable statement (vname = ...). If this project is compiled in C89/gnu89 mode (common for SD/FAST-era code), mixed declarations/statements can fail or at least warn. Move the prototype declaration up with the other locals (and just assign/reset it inside the loop) to keep the file C89-compatible and consistent with the surrounding style.
2c8b98e to
cb54999
Compare
Previously sdlib declared user function pointers as
int (*func)()but then calledfuncwith arguments. That's deprecated in C and an error in C++. This PR modified sdlib.c code generation to define the function prototypes properly.This change is