我收到以下代码的编译错误。我已经尽力了,但还是想不出来。任何帮助都将不胜感激。
#include <stdio.h>
#include <stdlib.h>
#define N 100
int counter=0;
struct node {
int value; };
struct node *p = (struct node *) malloc (N*sizeof (node));
void main()
{
int a = 5, b=6;
struct node * c = 0;
c = add(a,b);
}
void add(int m, int n)
{
struct node * pin_1;
struct node * pin_2;
struct node * pin_0;
pin_0->value = m;
pin_1->value = n;
pin_2->value = m + n;
counter++;
printf("value of out is %d /n", pin_2->value);
}GCC犯了个错误:
struct_check.c:9:错误:此处未声明的‘node’(不在函数中)
发布于 2016-10-03 10:03:31
首先,在语法上,你需要改变
struct node *p = (struct node *) malloc (N*sizeof (node));至
struct node *p = malloc (N*sizeof ( struct node));因为,node本身不是一个类型,除非您使用typedef来创建一个类型。
尽管如此,
p。pin_2和pin_0,这会调用未定义行为。在取消引用之前,您需要让这些指针指向一些有效的内存。void main()是过时的,而对于宿主环境,符合标准的签名至少将是int main(void)。struct node *p = malloc ( N *sizeof(*p));编写更健壮的语句。https://stackoverflow.com/questions/39829007
复制相似问题