c - 警告 C4013 : undefined; assuming extern returning int

标签 c

我收到另一个警告

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.hGet_Signature.h)中,您应使用不同名称替换 header 防护.

关于c - 警告 C4013 : undefined; assuming extern returning int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21953753/

相关文章:

c - 一次性对内存副本进行基准测试

iphone - AudioQueue 捕获并返回不同的缓冲区大小

c - 等待 child 完成

c - 将结构写入文本文件

c - 指针错误信息

c - 删除二叉树中仅通过引用传递节点的节点

c - 请解释一下C程序的这个功能是如何工作的?

c - 从字符串中删除空格,将单词添加到C中的数组中

c - 使用枚举数组和 typedef 数组编译 C 代码时出错

c - X86 汇编指令指针寻址