我有一个struct
:
typedef struct myStruct
{
const int *const array_ptr;
} myStruct_s;
我有一个const
的int
数组:
const int constArray[SIZE1] =
{
[0] = 0,
[1] = 1,
[2] = 2,
//...
};
现在我有一个使用指定初始化器初始化的
myStruct_s
常量数组:const myStruct_s structArray[SIZE2] =
{
[0] =
{
.array_ptr = &constArray
},
//...
}
我收到了以下警告:
无法使用类型为“const int (*)[SIZE1]”的值来初始化类型为“const int *const”的实体
我该如何正确初始化这个指针?
我想避免以下情况:
const myStruct_s structArray[SIZE2] =
{
[0] =
{
.array_ptr = (const int *const) &constArray
},
//...
}
如果可能的话,因为我感觉我在告诉编译器:“我不知道我在做什么,请不要检查类型”……谢谢你的帮助 :)。
array_ptr = &constArray[0];
- Nadir[1] = 1
)从1开始。虽然不涉及问题,但看起来有点可疑。 - davmacenum
作为索引来填充数组。我从不使用魔法数字 :)。我有点过于快速地简化了我的代码! - Plouff