开发者

Struct with pointer to a function

开发者 https://www.devze.com 2023-01-01 07:52 出处:网络
In a C struct I have defined a function pointer as follows: typedef struct _sequence_t { const int seq[3];

In a C struct I have defined a function pointer as follows:

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

I wan开发者_StackOverflow社区t to initialize a var of that type globally with:

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

And I keep getting error telling me that there are too many initializers. How to work it out?


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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号