I'm trying to initialize an array of structs. The struct contains a function pointer as one of its data members. But my compiler is giving me an error complaining that The initializer element is not constant. How can I initialize the array with my declared function pointer?
typedef void (*write_func_ptr_t)( void**, size_t*, char*, const size_t);
typedef bool (*read_func_ptr_t)( char*, const void*, const size_t);
write_func_ptr_t generate_basic_msg_ptr;
read_func_ptr_t handle_basic_msg_ptr;
write_func_ptr_t generate_reg_msg_ptr;
read_func_ptr_t handle_reg_msg_ptr;
struct supported_msg_info
{
const char* const type;
const write_func_ptr_t write_func;
const read_func_ptr_t read_func;
};
static struct supported_msg_info SUPP_MESSAGES[] = {
{ "basic", generate_basic_msg_ptr, handle_basic_msg_ptr },
{ "registration", generate_reg_msg_ptr, handle_reg_msg_ptr }
};
const, they still wouldn't work because C initializer rules are very strict.