c警告:在常量表达式中使用const变量在C中是非标准的

use*_*250 3 c warnings

尝试将数组初始化为常量时,我​​收到此警告.

#2170-D在常量表达式中使用const变量在C中是非标准的

#file.h
typedef struct {
    // LED Blink Pattern
    .....
} LEDSeq

void addError(LEDSeq);
void runLEDErrors();
....

#file.c
const uint8_t MAXERRORS = 4;
LEDSeq errors[MAXERRORS];
uint8_t errorsLength = 0;
....
Run Code Online (Sandbox Code Playgroud)

本质上,它是一些代码,它将循环遍历在运行时添加的LED错误序列.我必须使用固定大小的数组,因为realloc在我的环境中不可用.代码都有效.我只是想知道为什么我会收到这个错误.

oua*_*uah 7

const对象不是在C,但只读对象的常数.在文件范围(或具有静态存储持续时间的任何数组)声明的数组必须具有常量表达式作为其元素数.

这是有效的:

#define MAXERRORS 4
LEDSeq errors[MAXERRORS];
Run Code Online (Sandbox Code Playgroud)