如何在C/C++中定义常量一维数组或二维数组?我处理的是嵌入式平台(Xilinx EDK),所以资源有限。
我想在第三方头文件中写下类似这样的内容
#define MYCONSTANT 5而是数组。喜欢
#define MYARRAY(index) { 5, 6, 7, 8 }最常见的方法是什么?
发布于 2011-08-01 06:26:39
在C++源文件中
extern "C" const int array[] = { 1, 2, 3 };在包含在C和C++源文件中的头文件中
#ifdef __cplusplus
extern "C" {
#endif
extern const int array[];
#ifdef __cplusplus
}
#endif发布于 2011-08-01 06:00:03
在C++中,最常见的定义常量数组的方法应该是,呃,定义一个常量数组:
const int my_array[] = {5, 6, 7, 8};您是否有理由认为在该嵌入式平台上会有一些问题?
发布于 2011-08-01 06:01:21
在C++中
const int array[] = { 1, 2, 3 };这很容易,但也许我没有正确理解你的问题。以上内容在C中不起作用,但请指定您真正感兴趣的语言。没有像C/C++这样的语言。
https://stackoverflow.com/questions/6892586
复制相似问题