【问题标题】:How to initialize array that declared inside struct?如何初始化在结构中声明的数组?
【发布时间】:2021-12-31 19:47:42
【问题描述】:

我正在开发 C 程序来读取门禁状态。我创建了一个结构,其中声明了两个数组。我想在定义该结构时初始化数组。 例如,

.h 文件中的结构声明:

typedef volatile struct
{

    uint8_t __near const * const people_in_input_ports[8];

    uint8_t __near const * const people_out_input_ports[8];

}GATE_ACCESS_CTRL_BLOCK;

.c 文件中的结构体定义:

GATE_ACCESS_CTRL_BLOCK g_gate_acc_parameters    = { 
    .people_in_input_ports  = {&P12, &P4, &P4, &P4, &P6, &P6, &P6, &P6},                                                
    .people_out_input_ports = {&P14, &P14, &P2, &P14, &P14, &P5, &P5, &P1}
};

这里P12P4P6P5P2P14是对应端口的sfr地址。

我收到以下错误。

E0520029:Expected an expression
E0520029:Expected an expression

如何使用数组名来初始化结构内声明的数组?

【问题讨论】:

标签: arrays c struct initialization embedded


【解决方案1】:

在我的项目中,选择了 C90 标准,它不支持编译器设置中的那种初始化。将其更改为 C99 标准即可。

【讨论】:

  • 或者直接删除指定的初始化器。
猜你喜欢
  • 1970-01-01
  • 2018-05-20
  • 2019-11-26
  • 2011-02-08
  • 1970-01-01
  • 2017-09-24
  • 1970-01-01
  • 2020-12-14
  • 2016-11-05
相关资源
最近更新 更多