我正在将一个简单的 socket
客户端程序从 Linux 迁移到 Windows (VS2012)。该程序使用常规的close
、read
和write
函数。
在 VS2012 中编译时,我收到以下警告:
warning C4996: 'close': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _close
warning C4996: 'write': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _write
warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read
解决方案很简单 - 只需添加下划线 - 但是......
close
和 _close
、read
和 _read
、write 之间的真正区别是什么
和 _write
?
只是更改为下划线版本将保持相同的行为?
最佳答案
When compiling in VS2012, I´m getting the following warnings
哇,这些都是滑稽的误导性信息。干得好,微软。
他们似乎暗示 _close
、_read
和 _write
在某种程度上是 ISO C++ 函数。
他们不是!
What's the real difference between
close
and_close
,read
and_read
,write
and_write
?
Microsoft 显然重新实现了 POSIX 函数 close
、read
和 write
。不同之处在于,在重新实现时,他们选择用前导下划线重命名这些函数,因为 ISO C++ 标准规定前导下划线是实现(即 Visual Studio)应该用于内部/内置函数的内容。
Just changing to the underscore version will preserve the same behaviour ?
我不打算在这里列举各种潜在的差异。当然,有关这些功能如何工作以及如何使用它们的完整信息,请阅读它们的文档。不过,直接的答案是不假设其行为与同名 POSIX 函数的行为相同。
关于c++ - close vs _close, read vs _read, write vs _write - 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36438732/