Why gcc is complaing about gets()

不想你离开。 提交于 2019-12-24 00:23:33

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/35358767/why-gcc-is-complaing-about-gets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!