C 铸造无效时的警告**

C 铸造无效时的警告**,c,gcc,gcc-warning,C,Gcc,Gcc Warning,我正试图为一个接受void**的函数强制转换一个指向void**的结构指针 typedef struct { uint64_t key; // the key in the key/value pair void *value; // the value in the key/value pair } HTKeyValue, *HTKeyValuePtr; HTKeyValuePtr payload = (HTKeyValuePtr)malloc(sizeof(H

我正试图为一个接受
void**
的函数强制转换一个指向
void**
的结构指针

typedef struct {
  uint64_t   key;    // the key in the key/value pair
  void      *value;  // the value in the key/value pair
} HTKeyValue, *HTKeyValuePtr;

HTKeyValuePtr payload = (HTKeyValuePtr)malloc(sizeof(HTKeyValue));
int success = (HTKeyValuePtr) LLIteratorGetPayload(i, (void**) &payload);
给我一些警告:

hashtable.c:161:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
hashtable.c:161:19: warning: initialization makes integer from pointer without a cast [enabled by default]
发生什么事了?我该如何解决这个问题

p、 对不起,如果这是一个重复的任何其他问题。有很多类似的问题,但我找不到一个适合我的情况并且我理解的问题。

int success=(HTKeyValuePtr)LLIteratorGetPayload(I,(void**)和payload)

您正在将指针赋给int

此外,google告诉我,
LLIteratorGetPayload
的第一个参数应该是
LLIter
,它原来是
typedef void*
。我猜
I
是一个整数。这就是第一个错误的原因。

int success=(HTKeyValuePtr)LLIteratorGetPayload(i,(void**)和payload)

您正在将指针赋给int


此外,google告诉我,
LLIteratorGetPayload
的第一个参数应该是
LLIter
,它原来是
typedef void*
。我猜
I
是一个整数。这就是第一个错误的原因。

不要强制转换
malloc()的返回值。
@H2CO3是的,在这种情况下我不应该这么做。习惯。不要强制转换
malloc()
的返回值@H2CO3是的,在这种情况下我不应该这么做。顺便说一句,我是个骗子。这只是HTKeyValuePtr的演员阵容。哦,好吧。我只能猜这么多。。。现在我看到
LLIteratorGetPayload
返回一个
int
。这就解释了双重错误。我忘记了返回类型,在左边更正了它,在右边忘记了更改。顺便说一句,我是一个错误者。这只是HTKeyValuePtr的演员阵容。哦,好吧。我只能猜这么多。。。现在我看到
LLIteratorGetPayload
返回一个
int
。这就解释了双重错误。我忘记了返回类型,在左边更正了它,在右边忘记了更改它。