I am implementing a generic Hash Table in C using macros.
As one example, I defined key, value types as
#define h_key_type int
#define h_val_type int
Then I defined put function as:
#define H_PUT(key_type, val_type) \
void key_type##_put(...)
H_PUT(h_key_type, h_val_type);
However, after preprocessing the processed source codes become
void h_key_type_put(...)
Even I changed the function declaration as:
#define H_PUT() \
void h_key_type##_put(...)
it's still replaced as:
void h_key_type_put(...)
So I have to use
#define H_PUT(key_type, val_type) \
void key_type##_put(...)
H_PUT(int, int)
to make it work.
But it's not convenient since I either have to introduce a gigantic define block, or I have to type key, value types for each function, which is not elegant.
Any ideas?