[英]STM32: storing a map of addresses in an array
I'm trying to store a map of addresses in an array. 我正在尝试在数组中存储地址映射。
The following code snippet works as expected on my STM32F767ZI, but compiles with a warning... 以下代码片段在我的STM32F767ZI上按预期工作,但编译时出现警告...
intptr_t addressMap[2];
int* a=NULL;
int* b=NULL;
*a=10;
*b=20;
addressMap[0]=(intptr_t) a;
addressMap[1]=(intptr_t) b;
int* c=addressMap[0];
compiles with a warning: 编译警告:
initialization makes pointer from integer without a cast [-Wint-conversion]
at the last line ( int* c=addressMap[0];
). 在最后一行(
int* c=addressMap[0];
)。
I also tried uint32_t
and int32_t
as the data type of the addressMap
array. 我还尝试了
uint32_t
和int32_t
作为addressMap
数组的数据类型。 Same warning. 同样的警告。
According to this document ( http://www.keil.com/support/man/docs/armcc/armcc_chr1359125009502.htm ) addresses are 32 bit wide (as expected). 根据该文档( http://www.keil.com/support/man/docs/armcc/armcc_chr1359125009502.htm ),地址是32位宽(如预期的那样)。
How may I write my code without this warning? 如果没有这个警告我怎么写我的代码?
How may I write my code without this warning?
如果没有这个警告我怎么写我的代码?
as the warning says just add a cast doing 正如警告所说,只需添加一个演员
int* c = (int*) addressMap[0];
to avoid the warning initialization makes pointer from integer without a cast [-Wint-conversion]
避免警告
initialization makes pointer from integer without a cast [-Wint-conversion]
But, I recommend you to not use intptr_t
but directely int*
if the goal of addressMap is to contains pointers to int , thanks to that you do not need cast at all : 但是,我建议你不要使用
intptr_t
但directely int*
如果addressMap的目标是包含指针为int,多亏了你不需要投都:
int * addressMap[2];
int* a=NULL;
int* b=NULL;
*a=10;
*b=20;
addressMap[0] = a;
addressMap[1] = b;
int* c = addressMap[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.