来自 typedef 的不兼容类型在 c 中定义的指针
Incompatible type from typedef defined pointer in c
使用 VS 2019,以下 C 代码函数给我 C4133 警告以及整个代码中的其他几个区域。警告指出:
"Warning C4133 '=': incompatible types - from 'client *' to 'client_t"
但是,从我的 typedef 客户端* 和 client_t 应该是同一件事,除非我误解了 typdef 的语法。下面是我收到此警告的一个实例:
//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
时,编译器会说 "huh, struct client
is neither client
nor struct _client
-- be wary!"
使用 VS 2019,以下 C 代码函数给我 C4133 警告以及整个代码中的其他几个区域。警告指出: "Warning C4133 '=': incompatible types - from 'client *' to 'client_t"
但是,从我的 typedef 客户端* 和 client_t 应该是同一件事,除非我误解了 typdef 的语法。下面是我收到此警告的一个实例:
//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
时,编译器会说 "huh, struct client
is neither client
nor struct _client
-- be wary!"