strndup的隐式声明 [英] implicit declaration of strndup

查看:630
本文介绍了strndup的隐式声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这样的警告:( -std = C99 -pedantic

 警告:函数'strndup[-Wimplicit函数声明]隐式声明

但我进口这些库:

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT;

那么,什么? (


  // file.c中:
    的#includefile.h
    strndup(...)
// file.h:
    #包括LT&;&stdio.h中GT;
    #包括LT&;&stdlib.h中GT;
    #包括LT&;&string.h中GT;


解决方案

这个问题是你的 -std = C99 选项的使用。由于 strndup()不是的C99的一部分,你问的编译器进入标准兼容模式,它不会提供原型吧。它仍然林克斯球场的,因为你的C库有它。

虽然你可能能够哄 GCC 成自己指定的宏功能提供的话,我会说这并没有太大的意义是在C99符合模式的要求GNU扩展的例子。 GCC 已经为此提供了一个模式,这将解决您的警告: -std = gnu99

I'm getting this warning: (-std=c99 -pedantic)

warning: implicit declaration of function ‘strndup’ [-Wimplicit-function-declaration]

but I'm importing these libs:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

So what?! :(


// file.c:
    #include "file.h"
    strndup(...)
// file.h:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

解决方案

The issue is your usage of the -std=c99 option. Since strndup() isn't part of C99, and you're asking the compiler to go into standards compliant mode, it won't provide the prototype for it. It still links of course, because your C library has it.

While you may be able to coax gcc into providing it by specifying feature macros yourself, I'd say it doesn't make much sense to be in C99 compliance mode and ask for GNU extensions for example. gcc already provides a mode for this, which will solve your warning: -std=gnu99.

这篇关于strndup的隐式声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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