Struct with a function pointer

In the C structure, I defined a function pointer as follows:

typedef struct _sequence_t { const int seq[3]; typedef void (* callbackPtr)(); } sequence_t; 

I want to initialize var of this type globally with

 sequence_t sequences[] = { { { 0, 1, 2 }, toggleArmament }, }; 

And I keep getting an error telling me that there are too many initializers. How it works?

+1
source share
1 answer

typedef used to declare an alias for a type. Since you have the actual member here, remove the internal typedef .

 typedef struct _sequence_t { const int seq[3]; void (* callbackPtr)(); } sequence_t; 
+11
source

Source: https://habr.com/ru/post/1390943/


All Articles