0

I'm calling fdopen. On Windows, using Visual C++ 2010, when I call it I get a warning saying

Warning 1 warning C4996: 'fdopen': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fdopen.

On Linux (g++ 4.8.2) it works.

When I switch to _fdopen, Visual C++ stops complaining, but g++ can't find it. Since g++ does find fdopen, I don't think it's the issue described here. And anyway, I'm not specifying -std=c++11 .

Should I use _fdopen? Should I use fdopen and ignore the warning?

Community
  • 1
  • 1
zmbq
  • 38,013
  • 14
  • 101
  • 171
  • You should consider using a cross-platform framework like [Qt](http://qt.io) or [POCO](http://pocoproject.org/) if you care about both POSIX & Windows. – Basile Starynkevitch May 04 '15 at 08:50

1 Answers1

2

fdopen is not part of the C++ standard, but POSIX. While pretty much every C++ compiler maintainer wants to fulfill the C++ standard, there is little consensus if and how POSIX is supported.

Essentially, fdopen falls into the same category as any completely platform specific function; it´s just different on different systems. If the warning bugs you, you can use some preprocessor stuff to use one part of the code in Windows and another in Linux, eg. in your own fdopen-wrapper.

About the message that _fdopen is ISO C++ conformant: The C++ standard says something like everything with _ in the beginning is compiler-specific. So yes, in that point it´s conformant.

deviantfan
  • 11,268
  • 3
  • 32
  • 49
  • 1
    It's good to remember that POSIX is a standard which builds on ISO C, and not C++. In particular, it says very little about the interaction with C++ facilities. That's why there's `fdopen` instead of `posix::fdstream`. Also, as it originates in the UNIX world, it's logical why Microsoft doesn't really support it. – MSalters May 04 '15 at 08:45
  • Thanks. I'll just add a pragma that disables the warning on Visual C++ and that's it. – zmbq May 04 '15 at 10:06