【发布时间】:2012-02-24 07:45:05
【问题描述】:
如何使用 gcc 编译 lex 文件而不收到以下警告?
lex.yy.c: In function `yy_init_buffer':
lex.yy.c:1688: warning: implicit declaration of function `fileno'
lex.l: In function `storeLexeme':
lex.l:134: warning: implicit declaration of function `strdup'
这些是我包含的库。
%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
%}
函数 yy_init_buffer 不在文件中。下面是函数storeLexeme。
int storeLexeme() {
for (int i = 0; i < count; i++) {
char *curr = *(symbolTable + i);
if (strcmp(curr, yytext) == 0) {
return i;
}
}
char *lexeme = (char *)malloc(sizeof(char *));
lexeme = (char *)strdup(yytext);
symbolTable[count] = lexeme;
count++;
return (count - 1);
}
如何删除警告?
【问题讨论】:
-
我更改了 flex 标签,因为它是关于 Adobe flex 而不是 GNU lex 克隆。
-
什么平台,UNIX 还是 Windows?
-
那些不是“库”;它们是“标题”。链接行中使用了库;源代码引用标题。