Skip to content
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

CLASS_SIGNALMAININ should ensure that the variable has the correct type/size #2142

Closed
Spacechild1 opened this issue Nov 23, 2023 · 0 comments · Fixed by #2143
Closed

CLASS_SIGNALMAININ should ensure that the variable has the correct type/size #2142

Spacechild1 opened this issue Nov 23, 2023 · 0 comments · Fixed by #2143
Labels
improvement improves an existing functionality without adding new features subject:API "External Programming Interface" (things concerning development of externals)

Comments

@Spacechild1
Copy link
Contributor

Spacechild1 commented Nov 23, 2023

The CLASS_SIGNALMAININ macro implicitly expects a variable of type t_float. If you accidentally pass a variable of the wrong type (e.g. double in single-precision Pd), the compiler silently accepts it and you get garbage at runtime.

With C11 we could actually check the type/size with _Static_assert (https://en.cppreference.com/w/c/language/_Static_assert). I think modern toolchains default to C11< anyway, but we can use conditional compilation to keep C89 compatibility.

Also, we could use offsetof (https://en.cppreference.com/w/c/types/offsetof) to calculate the member offset, instead of the terrible NULL pointer cast trick. In fact, offsetof is part of the C89 standard!

@Spacechild1 Spacechild1 added subject:API "External Programming Interface" (things concerning development of externals) improvement improves an existing functionality without adding new features labels Nov 23, 2023
@Spacechild1 Spacechild1 changed the title CLASS_SIGNALMAININ should ensure that the variable has the correct type CLASS_SIGNALMAININ should ensure that the variable has the correct type/size Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement improves an existing functionality without adding new features subject:API "External Programming Interface" (things concerning development of externals)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant