我收到此警告:(-std=c99 -pedantic
)
warning: implicit declaration of function ‘strndup’ [-Wimplicit-function-declaration]
但我正在导入这些库:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
那又怎样?! :(
// file.c:
#include "file.h"
strndup(...)
// file.h:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
最佳答案
问题是您对 -std=c99
选项的使用。由于 strndup()
不是 C99 的一部分,并且您要求编译器进入标准兼容模式,它不会为其提供原型(prototype)。它当然仍然链接,因为你的 C 库有它。
虽然您可以通过自己指定功能宏来诱导 gcc
提供它,但我认为处于 C99 兼容模式没有多大意义和 例如要求 GNU 扩展。 gcc
已经为此提供了一个模式,它将解决您的警告:-std=gnu99
。
关于c - 使用 -std=c99 的隐式声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39926605/