C 为什么生成此代码“a”;来自不兼容指针类型的赋值;警告
我正在自己编写一个shell,对于下面的代码(只是重要的几行代码),我总是收到“来自不兼容pointertype的赋值”的警告 结构声明在上面几行:C 为什么生成此代码“a”;来自不兼容指针类型的赋值;警告,c,arrays,shell,pointers,struct,C,Arrays,Shell,Pointers,Struct,我正在自己编写一个shell,对于下面的代码(只是重要的几行代码),我总是收到“来自不兼容pointertype的赋值”的警告 结构声明在上面几行: Pargs* parg = malloc(sizeof (Pargs)); 也许我没有看到我自己的失败,但我从几个小时以来一直在看这句话,我不知道为什么这是不正确的 PS:如果有人需要更多的代码或信息,请毫不犹豫地询问,我还有很多;) 您可以在结构本身中引用typedefPargs。这不起作用,因为它是指向不完整类型的指针,在给出完整定义之前,您
Pargs* parg = malloc(sizeof (Pargs));
也许我没有看到我自己的失败,但我从几个小时以来一直在看这句话,我不知道为什么这是不正确的
PS:如果有人需要更多的代码或信息,请毫不犹豫地询问,我还有很多;)
您可以在结构本身中引用typedefPargs
。这不起作用,因为它是指向不完整类型的指针,在给出完整定义之前,您无法引用它
你可以这样做-
typedef struct name // give any desired name to structure
{
struct name *next; //use struct's name to declare pointer next
char* command;
char* args[11];
} Pargs;
Pargs* parg = malloc(sizeof (Pargs));
typedef struct
{
struct Pargs* next;
char* command;
char* args[11];
} Pargs;
typedef struct name // give any desired name to structure
{
struct name *next; //use struct's name to declare pointer next
char* command;
char* args[11];
} Pargs;