使用时gets()
在我的代码中,编译器大喊
warning: the 'gets' function is dangerous and should not be used.`
and
warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638)
[-Wdeprecated-declarations]
有什么具体原因吗?
有人可以解释为什么编译器会这样显示......?
是的,因为,gets()
函数很危险,因为它存在缓冲区溢出问题。任何人都应该避免使用它。
Also, regarding the warning with -Wdeprecated-declarations
, gets()
is no longer a part of C
standard [C11
onwards]. So, C libraries compilers are not bound to support that any more. It can be removed in future. To warn the developer about the potential pitfall and to discourage the further usage of gets()
, the compiler## emits the warning message.
(##) To be pedantic, the warning is not generated by the compiler (gcc
) all by itself, rather caused by a pragma
or attribute on the implementation of gets()
in the glibc
that causes the compiler to emit the warning. [Courtesy, FUZxxl, from the dupe answer.]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)