Deprecated commands in Visual C++

2019-08-15 01:55发布

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

2条回答
一夜七次
2楼-- · 2019-08-15 02:36

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.

查看更多
SAY GOODBYE
3楼-- · 2019-08-15 02:47

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

查看更多
登录 后发表回答