aambrozkiewicz
aambrozkiewicz

Reputation: 552

Struct with pointer to a function

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 want 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?

Upvotes: 1

Views: 646

Answers (1)

kennytm
kennytm

Reputation: 523784

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;

Upvotes: 11

Related Questions