Recently I study C and there is what I can't understand.
I knew and found that gets( ) function returns char *.
char * gets(char *buffer)
#include <stdio.h>
int main(void)
{
char str[20], *p;
p = gets(str) /* <- gcc said warning: assignment ~. */
}
definitely p
is char *
type and the return type of gets( )
is also char *
.
Then why gcc said warning:
assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] ?
Well it's working... but I just expected compiling with no any messages.
Edit:
char * gets(char *buffer)
was exist but now removed from language.But it is still in library.
Then ,with implicit declaration,
gets
is compiled with default return valueint
.Though
gets
works well, It's very dangerous to use. Nowfgets
much better choice thangets
In addtion, I wanna know that how gets
is exist on header file.
#if __CLIBC_USE (DEPRECATED_GETS)
/* Get a newline-terminated string from stdin, removing the newline.
This function is impossible to use safely. It has been officially removed from ISO c11 and ISO c++14, and we have also removed it from the _GNU_SOURCE feature list. It remains available when explicitly using an old ISO C, Unix, or POSIX standard.
This function is a possible cancellation point and therefore not marked with __THROW. */
extern char *gets (char *__s) __wur __attribute_deprecated__;
#endif
I could understand #ifdef that comments told me and how function is declared to be used.
Thank you for everyone! (_ _ )