C 错误:初始化类型时类型不兼容
我想获取C 错误:初始化类型时类型不兼容,c,pointers,casting,C,Pointers,Casting,我想获取REQ\u ONE的内容。最初我只是使用: REQ\u ONE*reqReg=FIND(地址) 但是我的代码分析器抱怨说指向void的指针是不允许的。所以我想转换结构的类型来解决这个问题。我有很多不同的结构,所以我只想使用一个宏: error: incompatible types when initializing type 'REQ_ONE * {aka struct REQ_ONE *}' using type 'REQ_ONE {aka volatile struct REQ_O
REQ\u ONE
的内容。最初我只是使用:
REQ\u ONE*reqReg=FIND(地址)
但是我的代码分析器抱怨说指向void的指针是不允许的
。所以我想转换结构的类型来解决这个问题。我有很多不同的结构,所以我只想使用一个宏:
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 *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)))
似乎缺少实际执行某些操作的代码在
FIND_W
扩展中,type
应该是dataType
@Steve,正在执行某些操作的代码行位于question@PaulOgilvie是的,更正了,谢谢,很抱歉通过了汇编,非常感谢,分析器仍然抱怨不允许使用指向void的指针。我认为这可以绕过警告。这可能是因为您正在向空指针添加值,因此编译器在计算加法时不知道指向的数据类型的大小。例如,如果它是指向int的指针,那么它将添加sizeof(int)*0x0000050ul
。因此,当前的代码方式无法避免该警告?您希望对该绝对地址和该添加地址做什么?
#define FIND_T(a, type) (*((volatile type *)a)) // wrong
#define FIND_T(a, type) ( ((volatile type *)a)) // no dereference