我一直在努力学习C语言 - 发出基本电话,看着它们失败,并试图弄清楚发生了什么。目前我正在使用fork()以及父进程和子进程之间的互操作。除了今晚我将-ansi
引入我的CFLAGS之外,一切都按预期工作了。那时,我从make获得了这些消息:
waitpid.c: In function ‘wait_for_child’:
waitpid.c:63:3: warning: implicit declaration of function ‘strsignal’ [-Wimplicit-function-declaration]
printf("child exited with signal %s\n", strsignal(WTERMSIG(child_status)));
^
waitpid.c:63:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
waitpid.c:64:3: warning: implicit declaration of function ‘WCOREDUMP’ [-Wimplicit-function-declaration]
if ( WCOREDUMP(child_status) ) {
^
gcc -C -E
的输出根本不同,具体取决于我是否指定-ansi。两者都展示了WIFEXITED,WEXITSTATUS,WIFSIGNALED和WTERMSIG的扩展,但只有非ANSI版本扩展了WCOREDUMP。它也是从sys / wait.h获得strsignal声明的那个。
我推断在ANSI C中不支持strsignal和WCOREDUMP,尽管我找不到任何明确的说法。还有其他方法来执行他们的功能吗?或者我错过了一些基本的东西?
完整代码位于http://pastebin.com/hQ2pR7fF。感谢。
答案 0 :(得分:2)