简体   繁体   English

如何初始化在结构中声明的数组?

[英]How to initialize array that declared inside struct?

I was developing C program to read status of door access.我正在开发 C 程序来读取门禁状态。 I created a struct in which two arrays were declared.我创建了一个结构,其中声明了两个 arrays。 I wanted to initialize the array at the time of definition of that structure.我想在定义该结构时初始化数组。 For example,例如,

Struct declaration in.h file: .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;

Struct definition in.c file: .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}
};

Here, P12, P4, P6, P5, P2 and P14 are sfr addresses of corresponding port.这里,P12、P4、P6、P5、P2、P14是对应端口的sfr地址。

I got the following error.我收到以下错误。

E0520029:Expected an expression
E0520029:Expected an expression

How to initialize arrays that are declared inside of a structure by using arrays' name?如何使用数组名称初始化在结构内部声明的 arrays?

Thanks & Regards,感谢和问候,

Sekar Natarajan塞卡·纳塔拉詹

Sorry to all,对不起大家,

In my project C90 standard language was selected which doesn't support that kind of structure initialization in compiler settings.在我的项目中,选择了 C90 标准语言,它不支持编译器设置中的那种结构初始化。 After changing it to C99, it works fine.将其更改为C99后,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM