我收到另一个警告
C4047: 'initializing' : 'char *' differs in levels of indirection from 'int'.
为什么我会收到这些警告?我在 MSDN 上读到,如果我编写的函数名称与我在头文件中编写的函数名称不同,它就会生成,或者它应该是 extern 函数。 有人可以解释一下吗?
我的相关代码是:
GetSignature.c
#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
#ifndef HEADERFILE_H
#define HEADERFILE_H
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#define chunk 255
#include <stdio.h>
#include <stdlib.h>
char *AllocMem(const char *);
#endif
最佳答案
我想这应该可以解决您的问题:替换这些行:
#ifndef HEADERFILE_H
#define HEADERFILE_H
与
#ifndef _ALLOC_MEM_H
#define _ALLOC_MEM_H
原因:每个头文件的头保护应该是唯一的,否则在包含多个头文件时会出现损坏。 (我猜您在所有头文件中都使用了相同的名称。)
已编辑:此外,在其他 header (Parse_Database.h
和 Get_Signature.h
)中,您应使用不同名称替换 header 防护.
关于c - 警告 C4013 : undefined; assuming extern returning int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21953753/