[英]error: incompatible types when initializing type
error: incompatible types when initializing type 'REQ_ONE * {aka struct REQ_ONE *}' using type 'REQ_ONE {aka volatile struct REQ_ONE}'
#define FIND_T(a, type) (*((volatile type *)a))
我想獲取REQ_ONE
的內容。 最初我只是使用:
REQ_ONE *reqReg = FIND(ADDRESS)
但是我的代碼分析器抱怨pointer to void not allowed
。 所以我想轉換結構的類型來解決這個問題。 我有很多不同的結構,所以我只想使用一個宏:
REQ_ONE *reqReg = FIND_W(ADDRESS, REQ_ONE);
並傳遞我想要尊重的類型參數。 但是,在我什至看到我的分析工具是否滿意之前,我收到了上述編譯錯誤。
#define TEST_ADDR 0x00652000UL
#define ADDRESS 0x00000500UL
#define FIND(v) ((void *)TEST_ADDR + v)
#define FIND_T(a, type) (*((volatile type *)a))
#define FIND_W(val, dataType) FIND_T(FIND(val), dataType)
typedef struct testing_t {
union {
struct {
uint32_t avr_one : 4;
uint32_t avr_one : 4;
uint32_t avr_one : 4;
uint32_t avr_one : 2;
uint32_t bcr_one : 4;
uint32_t test_one : 4;
uint32_t reserved : 1;
uint32_t bcr_three : 2;
uint32_t reserved1 : 1;
uint32_t test_one : 3;
uint32_t avg : 2;
uint32_t reserved2 : 1;
};
uint32_t VALUE32;
};
} REQ_ONE;
擴大這個產量:
REQ_ONE *reqReg = (*((volatile REQ_ONE *)((void *)0x00652000UL + 0x00000500UL)))
並且有一個*
太多,因此您取消引用您指向的內容並希望將其分配給指針類型變量。 錯誤在:
#define FIND_T(a, type) (*((volatile type *)a)) // wrong
#define FIND_T(a, type) ( ((volatile type *)a)) // no dereference
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.