你不会问你这个问题,已经要求编译器帮助你(没有冒犯!)。编译器是你的朋友。启用它的警告。对于
gcc -Wall yourcode.c
例如GCC给你
yourcode.c: In function ‘fill’:
yourcode.c: 11:5: warning: implicit declaration of function ‘send’
yourcode.c: At top level:
yourcode.c:15:5: warning: return type defaults to ‘int’
yourcode.c:22:5: warning: return type defaults to ‘int’
yourcode.c: In function ‘send’:
yourcode.c:26:5: warning: control reaches end of non-void function
yourcode.c: In function ‘main’:
yourcode.c:19:5: warning: control reaches end of non-void function
现在你知道你应该写一个原型功能send
或移动它是第一个使用上述定义。由于编译器假定默认返回类型为send
,您显然忘了指定它(因为您没有任何返回值,因此显然为void
)。对于main
返回类型int
和
return 0;
丢失。
随着该修饰的编译器会告诉你
yourcode.c: In function ‘fill’:
yourcode.c:12:5: error: incompatible type for argument 1 of ‘send’
yourcode.c.c:7:6: note: expected ‘struct xxx *’ but argument is of type ‘struct xxx’
,你会发现你在
send(*create);
它取消引用指针一个冗余*。注意:您不想取消引用您的指针,因为您必须将指针转发到send
而不是该值。将该行更改为
send(create);
etVoilà。
你尝试过发送(创建)吗? – RedX 2011-05-06 12:20:54
从一个非常快速的扫描...尝试'发送(创建);'不'发送(*创建);' – 2011-05-06 12:21:10