输入缓冲区出错

时间:2014-03-31 06:21:23

标签: c

我正在运行我的代码并在我的Input_buf()中遇到分段错误,即使我没有Input_buf函数。现在我已声明Input_buf的标题是:

#ifndef __GLOBAL_H 
#define __GLOBAL_H
#include <stdio.h>

#ifdef ALLOC 
#   define CLASS
#   define I(x) x
#else
#   define CLASS extern
#   define I(x)
#endif
#define MAXINP 2048

CLASS int Verbose   I(=0);
CLASS int No_lines  I(=0);
CLASS int Unix      I(=0);
CLASS int Public    I(=0);
CLASS char *Template    I(="lex.par");
CLASS int Actual_lineno I(=1);
CLASS int Lineno    I(=1);

CLASS char Input_buf[MAXINP];   //line buffer for input
CLASS char *Input_file_name;    //Input file name
CLASS FILE *Ifile;      //Input Stream
CLASS FILE *ofile;      //Output Stream

#endif

但我在链接的任何.c文件中没有Input_buf这样的功能。我使用gdb指出段发生的位置并显示Input_buf()。但是首先在此文件中使用Input_buf():

 PRIVATE head(int suppress_output)

 {
int transparent=0;
if(!suppress_output && Public)
    fputs("#define YYPRIVATE\n\n",Ofile);
if(!No_lines)
    fprintf(Ofile,"#line 1\"%s\"\n",Input_file_name);
while(fgets(Input_buf,MAXINP,Ifile))
{
    ++Actual_lineno;
    if(!transparent)
        strip_comments(&Input_buf);
    if(Verbose>1)
        printf("h%d: %s",Actual_lineno,Input_buf);
    if(Input_buf[0]=='%')
    {
        if(Input_buf[1]=='%')
        {
            if(!suppress_output)
                fputs("\n",Ofile);
            break;
        }
        else
        {
            if(Input_buf[1]=='(')
                transparent=1;
            else if(Input_buf[1]==')')
                transparent=0;
            else
                lerror(0,"ignoring illegal %%%c direct ( vv \n",Input_buf[1]);
        }
    }
    else if(transparent || isspace(Input_buf[0]))
    {
        if(!suppress_output)
            fputs(Input_buf,Ofile);
    }
    else
    {
        new_macro(Input_buf);
        if(!suppress_output)
            fputs("\n",Ofile);
    }
}
}

0 个答案:

没有答案