In which version of Visual Studio was a function introduced?

Viewed 123

We have a legacy project which was built in Visual Studio 2003.NET. Still work fine, but we're in the process of migrating it to Visual Studio 2019. Surprisingly few issues so far, though lots of warnings. One warning relates to fopen:

warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.

Converting this to fopen_s in VS2019 is trivial, but this doesn't build in Visual Studio 2003.NET (because fopen_s is not a recognised keyword). This can be solved with code like this:

#if (_MSC_VER <= 1310)
        // Visual Studio 2003.NET or earlier
        FILE* fp = fopen(pszTXT, "w");
#elif (_MSC_VER > 1310)
        // Newer versions of Visual Studio
        FILE* fp = NULL;
        fopen_s(&fp, pszTXT, "w");
#endif

When was fopen_s introduced into Visual Studio? The MSDN link was not immediately clear.

The question is intended to be general, not specific to fopen_s => is there documentation which shows which version of Visual Studio a keyword or method was introduced (or made obsolete).

2 Answers

From Visual C++ What's New 2003 through 2015 the _s functions were added in version 2005.

New CRT Features

  • Secure versions of several functions have been added. These functions handle errors in a better way and enforce stricter controls on buffers to help avoid common security flaws. The new secure versions are identified by the _s suffix.

For C++ features and changes support you can see cppreferences C++ compiler support to see in which compiler version a particular C++ feature was supported. This won't work for the _s functions though as they are a C feature, not C++.

The _s functions were introduced in C11 as part of Annex K, which basically nobody implemented except Microsoft.

Therefore, my suggestions are:

  • If your code is intended to be portable, do not change your code and use one of the macros Microsoft provides to disable those warnings. Another portable option is using C++'s facilities for the same task rather than C's.

  • If the code is not intended to be portable and you need more options/control, then use Windows-native functions like CreateFileW instead (which, by the way, will avoid other issues like being able to open Unicode-encoded filenames etc.).

Related