![](/img/trans.png)
[英]typedef function pointer -> initialization from incompatible pointer type
[英]Incompatible type from typedef defined pointer in c
使用VS 2019,以下C代碼功能向我發出C4133警告以及整個代碼中的其他幾個區域。 警告狀態:“警告C4133'=':不兼容的類型-從'client *'到'client_t”
但是,除非我誤解了typdef的語法,否則我的typedef client *和client_t應該是同一個人。 以下是收到此警告的一種情況:
//Client information structure for linked list
typedef struct _client {
char NAME[30];
unsigned long PHONE;
unsigned long ID;
unsigned char CountryID;
struct client *next;
struct client *previous;
}client, *client_t;
/*Function to sequentually free every node in the doubly linked list
@param: client_t *head - reference pointer to the head pointer of the client linked list
*/
void RemoveClient(client_t *head) {
if (head)
{
client_t current = *head;
if (current && current->next) {
while (current) {
//Warning C4133 at the below line
current = (*head)->next;
free(*head);
*head = current;
}
}
else
{
free(*head);
}
current = NULL;
*head = NULL;
}
else printf("head is a NULL pointer");
}
謝謝Cyberbission的建議! 將我的結構內部的組件更改為_client,而不是使用稍后給定的client定義來解決很多對我的警告:
//Client information structure for linked list
typedef struct _client {
char NAME[30];
unsigned long PHONE;
unsigned long ID;
unsigned char CountryID;
struct _client *next;
struct _client *previous;
}client, *client_t;
發生的事情是您引用了一個不存在的,名為struct client
的正向聲明類型:
//Client information structure for linked list
typedef struct _client {
// ...
struct client *next;
struct client *previous;
}client, *client_t;
這有點棘手。 在聲明next
和previous
,您有一個名為struct _client
的類型。 此后不久,您就有了一個名為client
的typedef
。 不幸的是,這些都不是struct client
。 由於操作僅引用指針,而沒有取消引用指針,因此您沒有任何實際錯誤,但是當您引用next
,編譯器會說“呵呵, struct client
既不是client
也不是struct _client
-要警惕!”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.