Open Gerharddc opened 9 years ago
fopen_s
only works on VS, not portable, and generally I don't see how it would be any safer than fopen
.
@memononen Ok, I didn't realize that. Would it be fine if I just added "safe" versions as conditional code for VS because it seems that VS feels very strongly about this?
@memononen It seems that it actually became standard with C++11, or am I mistaken?
fopen_s is not part of any "official" c/c++ standard. It is Microsoft CRT only! See https://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx.
The definition of _CRT_SECURE_NO_WARNINGS for source files disables these functions and "removes" them from the headers.
@Hockenberry I have actually found it easiest to just disable the "STL checks" in the properties of the source file in VS. I don't see that the MSDN article points out that the functions are MS only. What I have found though is that according to http://en.cppreference.com/w/c/io/fopen fopen_s was introduced into ISO C++ as of C++11 with their references pointing towards :
C11 standard (ISO/IEC 9899:2011):
7.21.5.3 The fopen function (p: 305-306)
K.3.5.2.1 The fopen_s function (p: 588-590)
If memory serves me correct though, support for C++11 has to be enabled by using a flag on GCC and is not supported by default even though GCC has support for C++11. As far as I know, most modern compilers have support for C++11 with many already having support for some of the proposed C++17 features.
Visual Studio is complaining that some code like fopen is unsafe and deprecated claiming that fopen_s would be better. I can see that an attempt has been made to disable the warning but unfortunately it is still a lot of effort to really get it disabled. Is there any reason why the "unsafe" code has not been replaced with "safe" code yet?