This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430FR5739:MSP430编译器错误声明常量指针的常量数组

Guru**** 664280 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1275903/msp430fr5739-msp430-compiler-error-declaring-const-array-of-const-pointers

器件型号:MSP430FR5739

我在使用 MSP430编译器时遇到一个编译器错误( TI v21.6.0.LTS ),但当我 在这里使用在线 GDB 编译器测试代码(链接),它似乎没有问题。

我正在尝试将一个常量指针常量数组声明到 volatile uint16_t。 以下是我尝试在 CCS 中构建的配对版本的代码:

#define BUFF_SIZE 8
volatile int BufferA[BUFF_SIZE] = {0};
volatile int BufferB[BUFF_SIZE] = {0};

volatile int * const BUFFER_A_START = BufferA;
volatile int * const BUFFER_B_START = BufferB;

const volatile int * const arrayOfConstPointers[2] = {BUFFER_A_START, BUFFER_B_START};

int main(void)
{
    // I'm okay the #145-D warning since it's not the problem I'm trying to solve:
	int * ptr = arrayOfConstPointers[0];
	*ptr = 4;

	return 0;
}

... 但编译器在第8行中对 arrayOfConstPointers 的声明给出了一个错误:"表达式必须有一个常数值"。

对于 TI 编译器、是否有一些关于 const 的特殊规则?

另外、我知道可以在链接器命令文件中使用 run_start 执行类似操作、但这给了我带来了其他问题、如果无法执行我在这里尝试的操作、我将在另一篇文章中保存这些问题。

谢谢!