Inconsistencies in using function pointers
Description
Sometimes function pointers are defined with function types:
typedef void SOPC_ComEvent_Fct(SOPC_App_Com_Event event, uint32_t IdOrStatus, void* param, uintptr_t appContext);
SOPC_ReturnStatus SOPC_Toolkit_Initialize(SOPC_ComEvent_Fct* pAppFct);
but other times they are defined with function pointer types:
typedef void (*SOPC_ClientHelper_DisconnectCbk)(const uint32_t connectionId);
int32_t SOPC_ClientHelper_Initialize(const char* log_path,
int32_t log_level,
const SOPC_ClientHelper_DisconnectCbk disconnect_callback);
Analysis
It is better to use a single form to declare all function types or function pointers.
As there are no data pointer types in S2OPC, it makes more sense to use function types, and function pointer types should be changed to function types.
In this case, &
and *
operator may seem useless, as they are added by the compiler when missing, but they should be kept for clarity.
Example:
typedef void SOPC_ClientHelper_DisconnectCbk(const uint32_t connectionId);
SOPC_ClientHelper_DisconnectCbk* cbk = &foobar; /* cbk = foobar is also valid but should be avoided */
(*cbk)(cId); /* cbk(cId) is also valid but should be avoided */
(there is no warning that can be activated to check for the use of *
operator to dereference a function pointer)