使用struct中定义的类型作为struct中函数参数的类型

时间:2021-07-22 19:57:35
typedef struct flag
  {
           int8_t (*valid)(Flag flag);
    const uint8_t requiresValue;
    const char*   name;
          uint8_t active;
          char*   value;

  } Flag;

How do i have the parameter for *valid be Flag inside the struct?

如何在结构中使用* valid参数?

1 个解决方案

#1


1  

The typedef you are looking for is as follows:

您正在寻找的typedef如下:

typedef struct flag
  {
           int8_t (*valid)(struct flag flag);
    const uint8_t requiresValue;
    const char*   name;
          uint8_t active;
          char*   value;

  } Flag;

I changed Flag to struct flag. Note the lowercase flag due to the first line typedef struct flag.

我将Flag更改为struct flag。请注意由于第一行typedef结构标志引起的小写标志。

#1


1  

The typedef you are looking for is as follows:

您正在寻找的typedef如下:

typedef struct flag
  {
           int8_t (*valid)(struct flag flag);
    const uint8_t requiresValue;
    const char*   name;
          uint8_t active;
          char*   value;

  } Flag;

I changed Flag to struct flag. Note the lowercase flag due to the first line typedef struct flag.

我将Flag更改为struct flag。请注意由于第一行typedef结构标志引起的小写标志。