Why gcc is complaing about gets()

2019-07-15 06:59发布

问题:

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