Erreur de compilation en C

时间:2015-01-11 20:08:20

标签: c file header

从昨天开始,我在C语言中遇到了一个恼人的问题,你是我最后的希望......我不是C编程新手

我制作了一个包含5个.c文件及其标题的项目。 我的一个.c正在使用文件,因此在每个函数中我都有:

FILE* file = NULL;
file = fopen("xxx", "x");

显然,我包含了sdtio和stdlib .. 但是对于gcc,我每次都有这些错误。

file_rw.c: In function ‘load_scramble’:
file_rw.c:9:9: error: ‘file’ undeclared (first use in this function)
FILE* file = NULL;
      ^

请帮忙! 多克斯:)

1 个答案:

答案 0 :(得分:2)

这似乎不太可能,但我能想到的一种可能性是,有一些奇怪的宏用其他东西取代FILE,这使得这个简单的声明变得无用。您可以通过带有gcc标记的-E找到预处理翻译单元的输出(有关详细信息,请参阅man gcc)。

例如:

#include <stdio.h>

#define FILE

int main(void)
{
    FILE* file = NULL;

    return 0;
}

gcc中编译并出现以下错误:

prog.c: In function 'main':
prog.c:6:8: error: 'file' undeclared (first use in this function)
  FILE* file = NULL;
        ^
相关问题