警告C4013:未定义;假设外部返回int
我得到另一个警告是 C4047:“初始化”:“char*”与“int”的间接寻址级别不同 为什么我会收到这些警告?我在MSDN上读到,如果我在头文件中写入了不同的函数名,它就会生成,或者它应该是extern函数。 有人能解释一下吗 我的相关代码是: GetSignature.c警告C4013:未定义;假设外部返回int,c,C,我得到另一个警告是 C4047:“初始化”:“char*”与“int”的间接寻址级别不同 为什么我会收到这些警告?我在MSDN上读到,如果我在头文件中写入了不同的函数名,它就会生成,或者它应该是extern函数。 有人能解释一下吗 我的相关代码是: GetSignature.c #include "Parse_Database.h" #include "Alloc_Mem.h" #include "Get_Signature.h" int Get_Signature(const char *
#include "Parse_Database.h"
#include "Alloc_Mem.h"
#include "Get_Signature.h"
int Get_Signature(const char *filename) {
char *database = AllocMem(filename);
int error=0;
//ParseDatabase(database);
return 1;
}
AllocMem
#include "Alloc_Mem.h"
char *AllocMem(const char *filename) {
FILE *fp = NULL;
int ch = EOF;
char *buf = NULL, *tmp = NULL;
unsigned int size=0, index=0;
/*
Mallicous use of fopen(anyone could replace filename with a malicous modified file)
*/
fp = fopen(filename, "r");
if(fp == NULL) {
fprintf(stderr, "Can't open the signature database");
exit(1);
}
while(ch) {
fread(&ch, 1, 1, fp);
if(ch == EOF) {
ch = 0;
}
if(size <= index) {
size+=chunk;
tmp = realloc(buf, size);
if(!tmp) {
free(buf);
buf = NULL;
break;
}
buf = tmp;
}
buf[index++] = ch;
}
fclose(fp);
return buf;
}
#包括“Alloc_Mem.h”
char*AllocMem(常量char*filename){
FILE*fp=NULL;
int ch=EOF;
char*buf=NULL,*tmp=NULL;
无符号整数大小=0,索引=0;
/*
恶意使用fopen(任何人都可以用恶意修改的文件替换文件名)
*/
fp=fopen(文件名,“r”);
如果(fp==NULL){
fprintf(stderr,“无法打开签名数据库”);
出口(1);
}
while(ch){
fread(和ch,1,1,fp);
如果(ch==EOF){
ch=0;
}
如果(尺寸我想这将解决您的问题:更换以下线路:
#ifndef HEADERFILE_H
#define HEADERFILE_H
与
原因:每个头文件的头保护都应该是唯一的,否则在包含多个头文件时会出现损坏。(我猜你在所有头文件中都使用了相同的名称。)
编辑:在您的其他标题(Parse_Database.h
和Get_Signature.h
)中,您应使用不同的名称替换标题防护装置。了解错误发生的确切位置会很有帮助。我假设是这样
char *database = AllocMem(filename);
在GetSignature.c
中
通常,发生此错误是因为C编译器在调用某个函数时没有声明该函数(该函数取决于错误消息中提到的行)。发生此错误时,C编译器假定该函数返回int
您是否有包含防护装置:
#ifndef HEADERFILE_H
#define HEADERFILE_H
也在Parse_Database.h
中?如果是这样,它会阻止AllocMem
的声明被包括在内,因为HEADERFILE_h
已经定义
通常的习惯是将定义的宏命名为与头文件相同的名称。例如:
#ifndef ALLOC_MEM_H
#define ALLOC_MEM_H
感谢@starrify的编辑。我以后会使用反勾号。另外,请确保您已为退出()函数添加了#include
。
#ifndef HEADERFILE_H
#define HEADERFILE_H
#ifndef ALLOC_MEM_H
#define ALLOC_MEM_H