为什么GCC抱怨gets() [英] Why gcc is complaing about gets()

查看:127
本文介绍了为什么GCC抱怨gets()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码(简体):

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

#定义大小240

int main(void)
{
char word [SIZE];
gets(word);

返回0;
}

GCC为什么给我



№3.c:在函数'main'中:
№3.c:13:2:警告:函数'gets'的隐式声明[-Wimplicit-function-declaration ]



此警告吗?



GCC归宿为5.2.1



PS程序正在运行。



PPS我将永远不会使用gets(),我永远不会使用gets(),我永远不会使用gets()

解决方案< C标准不再支持/ div>

函数 gets ,因为它是不安全的函数。所以似乎函数声明已从标题< stdio.h> 中排除,现在编译器不知道 gets的声明是什么



来自C标准(前言)


6第三版取消并替换了第二版,ISO / IEC
9899:1999,经ISO / IEC 9899:1999 / Cor 1:2001,ISO / IEC
9899:1999 /纠正Cor 2:2004和ISO / IEC 9899:1999 / Cor 3:2007。与上一版相比,
的主要变化包括:


...

 -删除了gets函数(< stdio.h>)


This is my code(simplified):

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

#define SIZE 240

int main(void)
{
    char word[SIZE];
    gets(word);

    return 0;
}

Why GCC is giving me

№3.c: In function ‘main’: №3.c:13:2: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]

this warning?

GCC vesion is 5.2.1

P.S.The program is working.

P.P.S. I will never use gets(), I will never use gets(), I will never use gets(), I will never use gets()

解决方案

Function gets is not supported by the C Standard any more because it is an unsafe function. So it seems the function declaration was excluded from the header <stdio.h> and now the compiler does not know what is the declaration of the gets.

From the C Standard (Foreword)

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>)

这篇关于为什么GCC抱怨gets()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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