Deprecated commands in Visual C++

陌路散爱 提交于 2019-12-11 11:56:41

问题


When building a solution in Visual Studio 2013 of a project, I noticed that I am getting warnings for the following references:

warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\JCSocket.cpp 77 1
warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\JCSocket.cpp 82 1
warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\JCSocket.cpp 121 1
warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\MuninNodeServer.cpp 64 1
warning C4996: 'GetVersionExW': was declared deprecated src\plugins\disk\DiskTimeMuninNodePlugin.cpp 48 1
warning C4996: 'GetVersion': was declared deprecated src\plugins\external\ConsolePipe.cpp 12 1
warning C4996: 'GetVersionExW': was declared deprecated src\plugins\PerfCounterMuninNodePlugin.cpp 56 1
warning C4996: 'GetVersionExW': was declared deprecated src\plugins\uptime\UptimeMuninNodePlugin.cpp 34 1

Whenever I try to change it to the recommended IntelliSense command, it is saying:

IntelliSense: identifier "inet_ntop" is undefined \src\core\MuninNodeServer.cpp 64 31


回答1:


These errors are telling you what to do. Microsoft is nice like that.

gethostbyname -> getaddrinfo
inet_addr -> inet_pton
inet_ntoa -> inet_ntop

As far as GetVersionExW and GetVersion Microsoft recommends using the appropriate Version Helper Function.




回答2:


Visual Studio tells you this warning cause you trying to use unsecure function which means includes the body of the function

and the body can obviously contain a signed overflow and there's a prospect to get another compiling errors or perhaps its not supported in the newer library

by the way, its about how you use this function


Simply you can disable the warning by add the following line

#pragma warning( disable : 4996)

at the top of your code

Which disable warning error code 4996 and will work fine without any problems.

Another way:

  1. from the Solution Explorer right click on the project and choose Properties
  2. navigate to Configuration Properties >> C/C++ >> Advanced
  3. at the end just put 4996 in disable specific warning and click Apply >> Ok

Note: I prefer code way at all, It's more good to learn if you're not programming in visual studio or making a header file for your library



来源:https://stackoverflow.com/questions/26947496/deprecated-commands-in-visual-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!