繁体   English   中英

STM32:在数组中存储地址映射

[英]STM32: storing a map of addresses in an array

我正在尝试在数组中存储地址映射。

以下代码片段在我的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];

编译警告:

initialization makes pointer from integer without a cast [-Wint-conversion]

在最后一行( int* c=addressMap[0]; )。

我还尝试了uint32_tint32_t作为addressMap数组的数据类型。 同样的警告。

根据该文档( http://www.keil.com/support/man/docs/armcc/armcc_chr1359125009502.htm ),地址是32位宽(如预期的那样)。

如果没有这个警告我怎么写我的代码?

如果没有这个警告我怎么写我的代码?

正如警告所说,只需添加一个演员

int* c = (int*) addressMap[0];

避免警告initialization makes pointer from integer without a cast [-Wint-conversion]

但是,我建议你不要使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM