Hello,
I use functions, which I register as a callback (I set its address to a pointer to function). Sometimes the functions use the parameter(s) only for reading. Cppcheck 2.11 will suggets for that case:
style: Parameter 'pContext' can be declared as pointer to const. However it seems that 'Function' is a callback function, if 'pContext' is declared with const you might also need to cast function pointer(s). [constParameterCallback]
I think this might bring more problem. When I forcibly cast the function address to match the pointer, it might hide more serious mismatch (e.g. the pointer to function type is changed and I rely on compiler to do the checks for me). Such mismatch will do a crash, which might be difficul to find, if the handler is called only "sometimes".
I think the Cppcheck should be more silent for such cases.
Best Regards Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I agree that it is unfortunate that casting is mentioned in the the error message. The idea is that constParameterCallback is a separate ID which can be suppressed as needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I use functions, which I register as a callback (I set its address to a pointer to function). Sometimes the functions use the parameter(s) only for reading. Cppcheck 2.11 will suggets for that case:
I think this might bring more problem. When I forcibly cast the function address to match the pointer, it might hide more serious mismatch (e.g. the pointer to function type is changed and I rely on compiler to do the checks for me). Such mismatch will do a crash, which might be difficul to find, if the handler is called only "sometimes".
I think the Cppcheck should be more silent for such cases.
Best Regards Martin
I agree that it is unfortunate that casting is mentioned in the the error message. The idea is that constParameterCallback is a separate ID which can be suppressed as needed.
OK, I understood. Thank you for help and hint to suppress constParameterCallback