-
Notifications
You must be signed in to change notification settings - Fork 86
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
p_context pointers are declared as const pointers #93
Comments
In FSP, p_context is user input data, and the type it points to cannot be known. It is pointer-to-const type to limit compiler warnings/errors due to discarded const qualifier. These warnings/errors show up in all the C compilers we support if the const qualifier is removed and a pointer-to-const is used to initialize p_context without casting. There are no warnings/errors from our C compilers if a normal pointer is used to initialize p_context as written without casting. |
If the pointer constness differ, then either there is either a warning when assigning to As I would have thought the common use case for
it would make more sense to have Example what I mean, using the FSP can_fd_ek_ra6m5_ep example project: No warning here in hal_entry.c:
But here in can_fd_ep.c:
Above example will compile without warnings if the Of course my suggestion to change the type is based on the assumption the most common usage is to point to non-const data. |
I agree the most common use case is for p_context to point to non-const data. Changing this would be a compatibility break since it will introduce build errors for IAR. We cannot break compatibility in minor releases, so we will consider this for 4.0.0. |
Great. The approach to change it for v4.0 makes sense, |
Due to issues with many internal test configurations this relatively small change ended up taking more time than anticipated. Unfortunately, it did not make it in time for the v4.0.0 release. We will try to see if we can release it sooner than v5.0.0 if at all possible. |
This issue is tracked internally by SWFLEX-2991. |
What is the rationale to use a const pointer rather a normal void pointer for p_context fields?
According to the documentation this pointer is intended to hold user data and make it available to callback functions. Declaring this pointer as const means that the user data it holds cannot be modified from within the callback function.
This limits its use and while in C the const can be easily cast away using a type cast, in C++ this requires unnecessary const_casts to remove the constness.
I suggest to change p_context to a simple void * pointer so it can hold both const and non-const user data.
The text was updated successfully, but these errors were encountered: