I am using the function gets()
in my C code.
My code is working fine but I am getting a warning message
(.text+0xe6): warning: the `gets' function is dangerous and should not be used.
I want this warning message not to pop up. Is there any way?
I am wondering that there might be such possibilities by creating a header file for disabling some warnings. Or is there any option during compiling that can serve my purpose? Or may be there is a particular way of using gets()
for this warning not to pop up?
You shouldn't use the
gets
function at all, the manpage says to usefgets
instead.GCC does not provide the functionality that GCC does to disable warnings using pragmas. You must use the various warning options as flags to the compiler instead.
The obvious answer is to learn from what the compiler is trying to tell you - you should never, ever, use gets(), as it is totally unsafe. Use fgets() instead, which allows you to prevent possible buffer overruns.
There really is no good reason to use
gets()
. Even the C standard says it's obsolescent! Usefgets()
instead.[Edit]
It looks like the warning comes from the linker. Do you get warning when compiling with
-c
? (Which disables linking.)If you really want use it.
Here is answer From: http://www.gamedev.net/community/forums/topic.asp?topic_id=523641
If you use a reasonably recent version of gcc, you can use:
For example, if those headers produce a "floating point comparison is unsafe" error, you would use:
Unluckily, you cannot disable "-Wall" that way (that would be too easy, wouldn't it...), you have to do the individual warning options which -Wall enables by hand (at least, the conflicting ones).
Docs: http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas
EDIT: But it seems not work for gets warning... I tried on my pc.
I would heed the warning and replace
gets
. This is clear enough for me:If you really want to use it, try the flag
-fsyntax-only
.The manual in gcc website says: