簡體   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