如何删除警告以下“功能的隐式声明”? [英] How do I remove the following 'implicit declaration of function' warnings?

查看:485
本文介绍了如何删除警告以下“功能的隐式声明”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何编译与海湾合作委员会的文件法没有收到下列警告?

How do I compile the lex file with gcc without receiving the following warnings?

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'

这是我包括图书馆。

These are the libraries I included.

%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
%}

该函数yy_init_buffer不是在文件中。以下是函数storeLexeme。

The function yy_init_buffer is not in the file. The following is the function 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);
 }

我如何删除的警告?

How do I remove the warnings?

推荐答案

无论是的strdup 也不的fileno 是ISO C功能,它们是POSIX的一部分。

Neither strdup nor fileno are ISO C functions, they're part of POSIX.

现在无论他们是您的平台上取决于您的平台。

Now whether they're available on your platform depends on your platform.

如果您使用的是微软的开发工具,你可能想看看 _fileno 后者( 的fileno 在VC2005 pcated 德$ p $)。 的strdup 的一个相当优秀的版本,可以发现<一个href=\"http://stackoverflow.com/questions/252782/strdup-what-does-it-do-in-c/252802#252802\">here.

If you are using the Microsoft tools, you may want to look into _fileno for the latter (fileno was deprecated in VC2005). A rather excellent version of strdup can be found here.

虽然已经吹我自己的喇叭与code,你也可以使用 _strdup ,因为它取代了还德precated 的strdup : - )

Although, having blown my own horn with that code, you could also use _strdup since it replaces the also-deprecated strdup :-)

这些应该有希望的工作没关系,-是因为他们在 stdio.h中文件string.h ,你们两个已经使用包含文件。

These should hopefully work okay as-is since they're in stdio.h and string.h, two of the include files you're already using.

如果你使用的是UNIX的衍生物,这些功能应该在 stdio.h中用(的fileno )和文件string.h (为的strdup )。因为它看起来像你已经有包括这些文件,该问题很可能在其他地方。

If you're on a UNIX derivative, those functions should be available in stdio.h (for fileno) and string.h (for strdup). Given that it looks like you're already including those files, the problem is likely elsewhere.

一种可能性是,如果你在严格的模式,如 __ __ STRICT_ANSI 在GCC),那里既没有将被定义之一进行编译。

One possibility is if you're compiling in one of the strict modes like __STRICT_ANSI__ in gcc), where neither would be defined.

您应该看看你产生的lex.yy.c lex.l 文件顶部以确认该头文件的被包含的并检查命令行参数你传递给编译器。

You should have a look at the top of your generated lex.yy.c and lex.l files to confirm that the header files are being included and also check the command line parameters you're passing to the compiler.

这篇关于如何删除警告以下“功能的隐式声明”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆