我正处于创建 C 编译器的开始阶段。我只想做一些简单的错误处理。
有人可以解释一下为什么我仍然得到:
“‘中止’类型冲突”
即使我已经定义了 abort() 的函数原型(prototype)并且签名匹配?
#include <stdio.h>
#include <string.h>
#include "Concat.c"
/* Constant declarations */
const char TAB = '\t';
/* Variable Declarations */
char look; /* Lookahead character */
/* Declaring function prototypes */
void getChar();
void error(char*);
void abort(char*);
/* Read new character fron input stream */
void getChar(){
read(look);
}
/* Report an error */
void error(char* s) {
// printf("%s\n", s);
perror(s);
}
/* Report an error and halt (return in C) */
void abort(char *s) {
perror(s);
return;
}
/* Main Program */
int main(int argc, char *argv[]) {
/* tab test */
printf("%c\n", TAB);
/* error test */
char *p;
p = "Error Test";
error(p);
/* abort test */
p = "Abort Test";
abort(p);
}
最佳答案
7.22.4.1 The
abort
functionSynopsis
#include <stdlib.h> _Noreturn void abort(void);
. . .
关于C - 错误冲突类型。定义了函数原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38425889/