通过头文件禁用GCC警告消息? [英] Disable warning messages in GCC through header files?
问题描述
我使用我的C code函数获得()
。
我的code为工作正常,但我得到一个警告讯息
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?
推荐答案
答案显然是从什么编译器是想告诉你去学习 - 你应该永远,永远,使用gets(),因为它完全是不安全的。使用与fgets()代替,它允许您prevent可能的缓冲区溢出。
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.
#define BUFFER_SIZE 100
char buff[BUFFER_SIZE];
gets( buff); // unsafe!
fgets( buff, sizeof(buff), stdin ); // safe
这篇关于通过头文件禁用GCC警告消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!