开发者

C programming on IAR

开发者 https://www.devze.com 2023-01-30 01:56 出处:网络
I am coding on the IAR platform and want to do the following. I have a typedef as follows struct timer {

I am coding on the IAR platform and want to do the following. I have a typedef as follows

struct timer {
  uint32_t start;
  uint32_t 开发者_Go百科interval;
};

typedef (void) (*etimer_cb) (int,void*);

struct etimer {
  struct timer timer;
  struct etimer* next;
  etimer_cb p;
};

After these I declare the following variable:

struct etimer periodic;

but it comes up with an error:

"periodic" is declared with a never completed type.

How do I resolve this?


Remove the () from around void.
uint32_t is not a predefined type. You need to #include <stdint.h>.

#include <stdint.h>
struct timer{
  uint32_t start;
  uint32_t interval;
};
typedef void (*etimer_cb)(int, void *);
struct etimer{
  struct timer timer;
  struct etimer* next;
  etimer_cb p;
};

But I prefer to NOT hide the pointerness of the function

#include <stdint.h>
struct timer{
  uint32_t start;
  uint32_t interval;
};
typedef void etimer_cb(int, void *);
struct etimer{
  struct timer timer;
  struct etimer* next;
  etimer_cb *p;
};
0

精彩评论

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