CLASS_SIGNALMAININ should ensure that the variable has the correct type/size #2142
Labels
improvement
improves an existing functionality without adding new features
subject:API
"External Programming Interface" (things concerning development of externals)
The
CLASS_SIGNALMAININ
macro implicitly expects a variable of typet_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 terribleNULL
pointer cast trick. In fact,offsetof
is part of the C89 standard!The text was updated successfully, but these errors were encountered: