I have a pair of functions that both accept multiple parameters. Both function signatures are the same type except for one enum parameter:
typedef enum { a_1, a_2, a_3 } enum_a_t;
typedef enum_a_t * enum_a_p;
typedef enum { b_1, b_2 } enum_b_t;
typedef enum_b_t * enum_b_p;
void func_a(int ai, float af, enum_a_p ae_ptr) { /* blah */ }
void func_b(int ai, float af, enum_b_p ae_ptr) { /* blah */ }
Now because in my head I think of enums being implemented as integers, I thought maybe I could typedef a function that is compatible with both of these signatures, something like:
typedef void (* func_t)(int, float, int *);
But of course when assigning either of these functions to a variable of that type (e.g. func_t f_a = func_a
), llvm-gcc complains:
warning: incompatible pointer types initializing 'func_t' (aka 'void (*)(int, float, int *)') with an expression of type 'void (int, float, enum_a_p)' (aka 'void (int, float, enum_a_t *)') [-Wincompatible-pointer-types]
I realize it's only a warning and I can probably get away with it if I'm careful, but I was curious if there is a strict / type-safe way to do something like this in C?
I would like to not have a warning on assignment, and I would like to be able to treat these functions as a common type without having to change their declared parameter lists.
edit
This is a very small example of the problem I'm experiencing in a much larger code base. Changing the declared parameter lists would require typecasting all direct invocations of those functions elsewhere in the code - a major change that would require a lot of integration testing (days of testing then involving others (this is on a weird embedded platform)) in areas of the code I really don't need to be modifying.