[英]Incompatible type from typedef defined pointer in c
Using VS 2019, the following C code function is giving me C4133 warning as well as several other area's throughout my code. 使用VS 2019,以下C代码功能向我发出C4133警告以及整个代码中的其他几个区域。 The warning states: "Warning C4133 '=': incompatible types - from 'client *' to 'client_t"
警告状态:“警告C4133'=':不兼容的类型-从'client *'到'client_t”
However, from my typedef client* and client_t should be the same thing unless I misunderstand the syntax for typdef. 但是,除非我误解了typdef的语法,否则我的typedef client *和client_t应该是同一个人。 Below is one instance where I get this warning:
以下是收到此警告的一种情况:
//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");
}
Thank you Cyberbission for your suggestion! 谢谢Cyberbission的建议! Changing my components inside of the struct to _client instead of using the later given definition of client fixed alot of those warnings for me:
将我的结构内部的组件更改为_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;
What's happened is you're referencing a forward declared type that does not exist, named struct client
: 发生的事情是您引用了一个不存在的,名为
struct client
的正向声明类型:
//Client information structure for linked list
typedef struct _client {
// ...
struct client *next;
struct client *previous;
}client, *client_t;
This is a bit tricky. 这有点棘手。 At the time of your declarations of
next
and previous
, you have a type named struct _client
. 在声明
next
和previous
,您有一个名为struct _client
的类型。 Shortly thereafter, you have a typedef
named client
. 此后不久,您就有了一个名为
client
的typedef
。 Neither of those are struct client
, unfortunately. 不幸的是,这些都不是
struct client
。 Since the operations are only referencing the pointer, but not de-referencing them, you don't have any actual errors, but when you refer to next
, the compiler says "huh, struct client
is neither client
nor struct _client
-- be wary!" 由于操作仅引用指针,而没有取消引用指针,因此您没有任何实际错误,但是当您引用
next
,编译器会说“呵呵, struct client
既不是client
也不是struct _client
-要警惕!”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.