Skip to content

Add missing prototypes to user functions in sdlib.c - #23

Merged
sherm1 merged 1 commit into
open-sdfast:mainfrom
sherm1:generate_c_prototypes
Apr 27, 2026
Merged

sherm1 merged 1 commit into
open-sdfast:mainfrom
sherm1:generate_c_prototypes

Conversation

@sherm1

@sherm1 sherm1 commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Previously sdlib declared user function pointers as int (*func)() but then called func with 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 Reviewable

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_PROCNAME parameters 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 / packvar call 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.

Comment thread sdfast_main/sdinteg.c Outdated
Comment thread calc/decl.c Outdated
Comment thread calc/decl.c Outdated

@sherm1 sherm1 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sherm1 reviewed 5 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on sherm1).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sdfast_main/main.c
Comment thread calc/decl.c

@sherm1 sherm1 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sherm1 reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on sherm1).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread calc/decl.c
Comment on lines 768 to +776
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;
}

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@sherm1
sherm1 force-pushed the generate_c_prototypes branch from 2c8b98e to cb54999 Compare April 27, 2026 01:29
@sherm1
sherm1 merged commit 3011244 into open-sdfast:main Apr 27, 2026
1 of 3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants