c++ - close vs _close, read vs _read, write vs _write - 有什么区别?

标签 c++ sockets visual-studio-2012

我正在将一个简单的 socket 客户端程序从 Linux 迁移到 Windows (VS2012)。该程序使用常规的closereadwrite 函数。

在 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_closeread_readwrite 之间的真正区别是什么_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 函数 closereadwrite。不同之处在于,在重新实现时,他们选择用前导下划线重命名这些函数,因为 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/

相关文章:

c++ - push_back 在增加容量之前推送元素?

c++ - 无法对存储在容器中的指针调用公共(public)方法

linux - 如何在套接字关闭时唤醒 select()?

c# - PHP 到 C# - 套接字 - 文件随机损坏

sockets - 如何以最少的停机时间切换 TCP 监听套接字?

c++ - Dijikstra计算后如何打印路径?

c++ - 如何在没有项目的情况下在 Visual Studio 2012 中只编译一个文件(C++)?

asp.net-mvc - 使用 Visual Studio 或 TFS 在项目之间共享 Assets (图像/css/js)

visual-studio-2012 - 启动时程序崩溃

python - 如何使用 python 将指针输入发送到 C++ 程序?