Mic*_*ael 0 c embedded variables mplab
unsigned char rtc_time[6] = { pThis->hoursTens, pThis->hoursUnits, pThis->minutesTens, pThis->minutesUnits, pThis->secondsTens, pThis->secondsUnits };
Run Code Online (Sandbox Code Playgroud)
不编译.我收到错误(6次):需要持续表达
每个变量都声明为unsigned char.我已经尝试过(const)而没有运气.
This is in MPLAB X IDE, C language, using Hi-Tech-PICC compiler v9.65PL1.
What is the problem?
It works when I define the variable as below, but I need to use the variables above.
unsigned char rtc_time[6] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 };
Run Code Online (Sandbox Code Playgroud)
You cannot initialize an array with values whose values are unknown at compile-time. The values of your struct are unknown at compile-time and so are not const expressions.
Whereas 0x1, 0x2, ... are const expressions that can be evaluated at compile-time.
您可以声明一个数组,然后在运行时设置值,比如
unsigned char rtc_time[6];
...
rtc_time[0] = pThis->hoursTens;
//go on
Run Code Online (Sandbox Code Playgroud)