为什么 gcc 抱怨 gets()
Why gcc is complaing about gets()
这是我的代码(简化版):
#include <stdio.h>
#include <string.h>
#define SIZE 240
int main(void)
{
char word[SIZE];
gets(word);
return 0;
}
为什么 GCC 给我
№3.c: In function ‘main’:
№3.c:13:2: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]
这个警告?
GCC 版本为 5.2.1
P.S.The 程序正在运行。
P.P.S。我永远不会用gets(),我永远不会用gets(),我永远不会用gets(),我永远不会用gets()
C 标准不再支持函数 gets
,因为它是一个不安全的函数。所以似乎函数声明被排除在 header <stdio.h>
之外,现在编译器不知道 gets
.
的声明是什么
来自 C 标准(前言)
6 This third edition cancels and replaces the second edition, ISO/IEC
9899:1999, as corrected by ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC
9899:1999/Cor 2:2004, and ISO/IEC 9899:1999/Cor 3:2007. Major changes
from the previous edition include:
...
— removed the gets function (<stdio.h>)
这是我的代码(简化版):
#include <stdio.h>
#include <string.h>
#define SIZE 240
int main(void)
{
char word[SIZE];
gets(word);
return 0;
}
为什么 GCC 给我
№3.c: In function ‘main’:
№3.c:13:2: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]
这个警告?
GCC 版本为 5.2.1
P.S.The 程序正在运行。
P.P.S。我永远不会用gets(),我永远不会用gets(),我永远不会用gets(),我永远不会用gets()
C 标准不再支持函数 gets
,因为它是一个不安全的函数。所以似乎函数声明被排除在 header <stdio.h>
之外,现在编译器不知道 gets
.
来自 C 标准(前言)
6 This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, as corrected by ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC 9899:1999/Cor 2:2004, and ISO/IEC 9899:1999/Cor 3:2007. Major changes from the previous edition include:
...
— removed the gets function (<stdio.h>)