{"id":523,"date":"2014-06-18T14:00:00","date_gmt":"2014-06-18T14:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2014\/06\/18\/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1\/"},"modified":"2019-02-18T18:05:20","modified_gmt":"2019-02-18T18:05:20","slug":"c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1\/","title":{"rendered":"C Runtime (CRT) Features, Fixes, and Breaking Changes in Visual Studio 14 CTP1"},"content":{"rendered":"<p><em>(This is the second of two articles on changes to the C Runtime (CRT) in the Visual Studio &#8220;14&#8221; CTP. The first article, <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2014\/06\/10\/the-great-crt-refactoring.aspx\" target=\"_blank\">The Great C Runtime (CRT) Refactoring<\/a>, covered the major architectural changes to the CRT; this second article enumerates the new features, bug fixes, and breaking changes.)<\/em><\/p>\n<p>This list covers all of the major changes to the CRT that were made after the Visual Studio 2013 RTM and which are present in the Visual Studio &#8220;14&#8221; CTP. For a similar list covering changes to the C++ Standard Library, see Stephan&#8217;s article from June 6, <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2014\/06\/06\/c-14-stl-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1.aspx\" target=\"_blank\">C++14 STL Features, Fixes, And Breaking Changes In Visual Studio 2014<\/a>. The changes are grouped by the main CRT header with which they are associated, with one large change to the <code>printf<\/code> and <code>scanf<\/code> functions covered first.<\/p>\n<p>In the Visual Studio &#8220;14&#8221; CTP we have fully implemented the C99 Standard Library, with the exception of any library features that depend on compiler features not yet supported by the Visual C++ compiler (notably, <code>&lt;tgmath.h&gt;<\/code> is not implemented). There are undoubtedly some remaining conformance issues&#8211;we know of a few, including that <code>_Exit<\/code> is missing and <code>wcstok<\/code> has the wrong signature, and we are working to fix these. If you find a bug or a missing feature, please do report it on <a href=\"http:\/\/connect.microsoft.com\/visualstudio\" target=\"_blank\">Microsoft Connect<\/a>. If you report bugs now, there is a very good chance that we&#8217;ll be able to fix them before RTM.<\/p>\n<p>Please note that the documentation on MSDN has not yet been updated to include any of the changes covered in these blog posts.<\/p>\n<h3>Fixing the Wide String Format and Conversion Specifiers<\/h3>\n<p><strong><span style=\"color: #ff0000\">Updated April 7, 2015:&nbsp; <span style=\"color: #000000\">This feature was reverted in Visual Studio 2015 CTP6; it will not be present in Visual Studio 2015.&nbsp; We had many customers express concern about this change and we discovered several new issues when working with static libraries.<\/span><\/span><\/strong><\/p>\n<p><span style=\"text-decoration: line-through\">The biggest &#8220;breaking change&#8221; to the CRT in the Visual Studio &#8220;14&#8221; CTP is a change to how the wide string formatted I\/O functions (e.g., <code>wprintf<\/code> and <code>wscanf<\/code>) handle the <code>%c<\/code>, <code>%s<\/code>, and <code>%[]<\/code> (scanset) format and conversion specifiers.<\/span><\/p>\n<p><span style=\"text-decoration: line-through\">The wide string formatted I\/O functions were first implemented in the Visual C++ CRT in the early 1990s. They were implemented such that the <code>%c<\/code>, <code>%s<\/code>, and <code>%[]<\/code> specifiers mapped to a wide character or string argument. For example, this was the behavior (and remained the behavior through Visual C++ 2013):<\/span><\/p>\n<pre><span style=\"text-decoration: line-through\"> printf(\"Hello, %s!\\n\", \"World\"); \/\/ Lowercase s: narrow string printf(\"Hello, %S!\\n\", L\"World\"); \/\/ Capital S: wide string wprintf(L\"Hello, %s!\\n\", L\"World\"); \/\/ Lowercase s: wide string wprintf(L\"Hello, %S!\\n\", \"World\"); \/\/ Capital S: narrow string <\/span><\/pre>\n<p><span style=\"text-decoration: line-through\">This design has the advantage that the <code>%c<\/code>, <code>%s<\/code>, and <code>%[]<\/code> specifiers always map to an argument of the &#8220;natural&#8221; width for the function call. If you&#8217;re calling a narrow string formatted I\/O function, they map to a narrow character or string argument; if you&#8217;re calling a wide string formatted I\/O function, they map to a wide character or string argument. Among other things, this design made it easier to move from use of narrow strings to use of wide strings, via the macros in <code>&lt;tchar.h&gt;<\/code>.<\/span><\/p>\n<p><span style=\"text-decoration: line-through\">These functions were later standardized in C99, and unfortunately, the standardized behavior was different. In the C99 specification, the <code>%c<\/code>, <code>%s<\/code>, and <code>%[]<\/code> specifiers always map to a narrow character or string argument. The <code>l<\/code> (lowercase L) length modifier must be used to format a wide character or string argument. So, per the C99 specification, the following calls are correct:<\/span><\/p>\n<pre><span style=\"text-decoration: line-through\"> printf(\"Hello, %s!\\n\", \"World\"); \/\/ s: narrow string printf(\"Hello, %ls!\\n\", L\"World\"); \/\/ ls: wide string wprintf(L\"Hello, %ls!\\n\", L\"World\"); \/\/ ls: wide string wprintf(L\"Hello, %s!\\n\", \"World\"); \/\/ s: narrow string <\/span><\/pre>\n<p><span style=\"text-decoration: line-through\">This design has the advantage that the specifiers always have the same meaning, regardless which function is called. It has the disadvantage that it doesn&#8217;t match what was previously implemented in the Visual C++ CRT and it doesn&#8217;t work with the macros in <code>&lt;tchar.h&gt;<\/code>.<\/span><\/p>\n<p><span style=\"text-decoration: line-through\"><strong>In the Visual Studio &#8220;14&#8221; CTP, we have flipped the meaning of the <code>%c<\/code>, <code>%s<\/code>, and <code>%[]<\/code> specifiers for the wide formatted I\/O functions so that their behavior matches what is required by the C Standard.<\/strong> The meanings of the capital letter specifier equivalents (<code>%C<\/code> and <code>%S<\/code>) have also been changed, for consistency. In order to facilitate continued use of the <code>&lt;tchar.h&gt;<\/code> header we have also added a new length modifier, <code>T<\/code>, that means the argument is of the &#8220;natural&#8221; width, in effect giving the legacy behavior. So, for example, all of the following calls are correct:<\/span><\/p>\n<pre><span style=\"text-decoration: line-through\"> printf(\"Hello, %s!\\n\", \"World\"); \/\/ narrow string printf(\"Hello, %S!\\n\", L\"World\"); \/\/ wide string printf(\"Hello, %ls!\\n\", L\"World\"); \/\/ wide string printf(\"Hello, %Ts!\\n\", \"World\"); \/\/ natural width (narrow) wprintf(L\"Hello, %s!\\n\", \"World\"); \/\/ narrow string wprintf(L\"Hello, %S!\\n\", L\"World\"); \/\/ wide string wprintf(L\"Hello, %ls!\\n\", L\"World\"); \/\/ wide string wprintf(L\"Hello, %Ts!\\n\", L\"World\"); \/\/ natural width (wide) <\/span><\/pre>\n<p><span style=\"text-decoration: line-through\">This fairly small change has a very large effect on existing code. There are many millions of lines of code that expect the old behavior, and we recognize that we can&#8217;t just unconditionally break all of that code. While we encourage you to migrate code to use the conforming format strings mode, we are also providing a compile-time switch to enable you to revert the behavior back to the legacy mode. There are, therefore, two modes:<\/span><\/p>\n<ul>\n<li>\n<p><span style=\"text-decoration: line-through\"><strong>C99 Conformance Mode<\/strong>: In this mode, calls to the wide string formatted I\/O functions will get the correct behavior as is required by C99. This mode is enabled by default.<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"text-decoration: line-through\"><strong>Legacy Mode<\/strong>: In this mode, calls to the wide string formatted I\/O functions will get the legacy behavior for these three format specifiers, as they were implemented in Visual Studio 2013 and previous versions. To enable this mode, predefine the <code>_CRT_STDIO_LEGACY_WIDE_SPECIFIERS<\/code> macro when building your program.<\/span><\/p>\n<\/li>\n<\/ul>\n<p><span style=\"text-decoration: line-through\">This mode is configurable per executable module, so each DLL or EXE can independently specify which mode it requires. This mode is configurable only at compile-time and cannot be changed dynamically. Because the mode is per executable module, all source files that are linked into a single executable module must be compiled for the same mode (i.e., with or without <code>_CRT_STDIO_LEGACY_WIDE_SPECIFIERS<\/code> defined. If you try to mix-and-match objects at link-time where some objects required the legacy mode and some required the conformance mode, you&#8217;ll get a link-time mismatch error.<\/span><\/p>\n<p><span style=\"text-decoration: line-through\">If you have static libraries and you would like to enable those static libraries to be linked into modules that use either C99 conformance mode or legacy mode, you can do so by doing the following:<\/span><\/p>\n<ol>\n<li>\n<p><span style=\"text-decoration: line-through\">Ensure that the code in your static library does not use or otherwise handle (e.g. via pass through) format strings whose behavior is different between the two modes, and<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"text-decoration: line-through\">Predefine the <code>_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS<\/code> macro when compiling the source files for your static library. This is not another mode; it simply allows those files to be linked into a module using either conformance or legacy mode.<\/span><\/p>\n<\/li>\n<\/ol>\n<h3>&lt;assert.h&gt;<\/h3>\n<ul>\n<li>In previous versions, when <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/958x11bc.aspx\" target=\"_blank\">Edit-and-Continue (\/ZI)<\/a> was enabled, use of the <code>assert<\/code> macro might cause a spurious C4365 signed\/unsigned warning. This has been fixed (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/792554\/assert-macro-in-assert-h-causes-compiler-warning-c4365\" target=\"_blank\">Connect #792554<\/a>).<\/li>\n<\/ul>\n<h3>&lt;fenv.h&gt; and &lt;float.h&gt;<\/h3>\n<ul>\n<li>\n<p><strong><code>_clear87<\/code> and <code>_clearfp<\/code><\/strong>: In Visual Studio 2013, the <code>_clear87<\/code> and <code>_clearfp<\/code> functions in the CRT for x86 would fail to return the original floating point unit status if the CPU supported SSE2. This has been fixed.<\/p>\n<\/li>\n<li>\n<p><strong><code>fegetenv<\/code> and <code>fesetenv<\/code><\/strong>: In Visual Studio 2013, these functions were incorrectly implemented in the CRT for x86. There were two bugs: [1] a call to <code>fegetenv<\/code> would cause any pending, unmasked x87 floating point exceptions to be raised, and [2] the <code>fegetenv<\/code> function would mask all x87 floating point exceptions before returning and would thus return incorrect state. Because the <code>fesetenv<\/code> function uses the same underlying logic, it was impacted by these issues as well. Both of these issues have been fixed.<\/p>\n<\/li>\n<li>\n<p><strong>feholdexcept<\/strong>: In Visual Studio 2013, the <code>feholdexcept<\/code> function failed to mask all floating point point exceptions before returning. This has been fixed.<\/p>\n<\/li>\n<li>\n<p><strong><code>FLT_ROUNDS<\/code><\/strong>: In Visual Studio 2013, the <code>FLT_ROUNDS<\/code> macro expanded to a constant expression, which was incorrect because the rounding mode is configurable at runtime, e.g. via a call to <code>fesetround<\/code>. The <code>FLT_ROUNDS<\/code> macro is now dynamic and correctly reflects the current rounding mode (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806669\/flt-rounds-should-be-dynamic\" target=\"_blank\">Connect #806669<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong><code>\/fp:strict<\/code> Support<\/strong>: In Visual Studio 2013, if <code>&lt;fenv.h&gt;<\/code> was included in a C source file and that source file was compiled with <code>\/fp:strict<\/code>, the source file would fail to compile due to the presence of floating point arithmetic in a static initializer in an inline function in <code>&lt;fenv.h&gt;<\/code>. This has been fixed (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806624\/fenv-h-unusable-in-vs-2013\" target=\"_blank\">Connect #806624<\/a>).<\/p>\n<\/li>\n<li>\n<p>The following macros have been added to <code>&lt;float.h&gt;<\/code>: <code>FLT_DECIMAL_DIG<\/code>, <code>FLT_HAS_SUBNORM<\/code>, <code>FLT_TRUE_MIN<\/code>, <code>DBL_DECIMAL_DIG<\/code>, <code>DBL_HAS_SUBNORM<\/code>, <code>DBL_TRUE_MIN<\/code>, <code>LDBL_DECIMAL_DIG<\/code>, <code>LDBL_HAS_SUBNORM<\/code>, and <code>LDBL_TRUE_MIN<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>&lt;inttypes.h&gt;<\/h3>\n<ul>\n<li><strong>Format and conversion specifier macros can now be used with wide format strings<\/strong>: In Visual Studio 2013, the format and conversion specifier macros in <code>&lt;inttypes.h&gt;<\/code> were defined in such a way that they were unusable in wide format strings. This has been fixed (<a href=\"http:\/\/stackoverflow.com\/questions\/21788652\/how-do-i-concatenate-wide-string-literals-with-prid32-priu64-etc\" target=\"_blank\">StackOverflow #21788652<\/a>).<\/li>\n<\/ul>\n<h3>&lt;math.h&gt;<\/h3>\n<ul>\n<li>\n<p><strong>C++ Overloads of Math Library Functions<\/strong>: In previous versions, <code>&lt;math.h&gt;<\/code> defined some, but not all, of the C++ overloads for the math library functions. <code>&lt;cmath&gt;<\/code> defined the remaining overloads, so to get all of the overloads, one needed to include the <code>&lt;cmath&gt;<\/code> header. This was the cause of various annoyances; for example, if a source file included only <code>&lt;math.h&gt;<\/code> then attempted to call <code>sin<\/code> with an argument of integer type, the source file would not compile due to ambiguity during overload resolution. To resolve this issue, all C++ overloads have been removed from <code>&lt;math.h&gt;<\/code> and are now present only in <code>&lt;cmath&gt;<\/code> (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/807080\/acos-unsigned-long-long-int-is-ambiguous\" target=\"_blank\">Connect #807080<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong>Correctness Fixes in New C99 Math Library Functions<\/strong>: In Visual Studio 2013, we added support for the new C99 math library functions (see <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/07\/19\/c99-library-support-in-visual-studio-2013.aspx\" target=\"_blank\">Pat Brenner&#8217;s blog post from last year<\/a> for a list of what was added). We have fixed several correctness bugs in these functions, including:<\/p>\n<ul>\n<li><a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806656\/remainder-and-remquo-loop\" target=\"_blank\">Connect #806656: <code>remainder()<\/code> and <code>remquo()<\/code> loop<\/a><\/li>\n<li><a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806664\/scalbn-and-scalbln-have-poor-accuracy\" target=\"_blank\">Connect #806664: <code>scalbn()<\/code> and <code>scalbln()<\/code> have poor accuracy<\/a><\/li>\n<li><a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/807120\/erfc-27-has-poor-results\" target=\"_blank\">Connect #807120: <code>erf(27.)<\/code> has poor results<\/a><\/li>\n<li><a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/808674\/incorrect-exp2-results-for-too-small-large-arguments\" target=\"_blank\">Connect #808674: Incorrect <code>exp2<\/code> results for too small\/large arguments<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong><code>FP_ILOGB0<\/code> and <code>FP_ILOGBNAN<\/code><\/strong>: The <code>FP_ILOGB0<\/code> and <code>FP_ILOGBNAN<\/code> macros are now defined in <code>&lt;math.h&gt;<\/code>; they were previously defined incorrectly with leading underscores (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806666\/math-h-missing-fp-ilogb0-and-fp-ilogbnan\" target=\"_blank\">Connect #806666<\/a>).<\/p>\n<\/li>\n<\/ul>\n<h3>&lt;stdio.h&gt; and &lt;conio.h&gt;<\/h3>\n<ul>\n<li>\n<p><strong>Conforming Wide Format Specifiers<\/strong>: See the first section of this article for a lengthy description of the changes that have been made to the <code>%c<\/code>, <code>%s<\/code>, and <code>%[]<\/code> (scanset) format and conversion specifiers.<\/p>\n<\/li>\n<li>\n<p><strong>The <code>printf<\/code> and <code>scanf<\/code> functions are now defined inline<\/strong>: In order to support the two wide string format and conversion specifier modes, the definitions of all of the <code>printf<\/code> and <code>scanf<\/code> functions have been moved inline into <code>&lt;stdio.h&gt;<\/code>, <code>&lt;conio.h&gt;<\/code>, and other CRT headers. This is a breaking change for any programs that declared these functions locally without including the appropriate CRT headers. The &#8220;fix&#8221; is to include the appropriate CRT headers.<\/p>\n<\/li>\n<li>\n<p><strong>Format and Conversion Specifier Enhancements<\/strong>: The <code>%F<\/code> format\/conversion specifier is now supported. It is functionally equivalent to the <code>%f<\/code> format specifier, except that infinities and NaNs are formatted using capital letters.<\/p>\n<p>The following length modifiers are now supported:<\/p>\n<ul>\n<li><code>hh<\/code>: <code>signed char<\/code> or <code>unsigned char<\/code><\/li>\n<li><code>j<\/code>: <code>intmax_t<\/code> or <code>uintmax_t<\/code><\/li>\n<li><code>t<\/code>: <code>ptrdiff_t<\/code><\/li>\n<li><code>z<\/code>: <code>size_t<\/code><\/li>\n<li><code>L<\/code>: <code>long double<\/code><\/li>\n<\/ul>\n<p>In previous versions, the implementation used to parse <code>F<\/code> and <code>N<\/code> as length modifiers. This behavior dated back to the age of segmented address spaces: these length modifiers were used to indicate far and near pointers, respectively, as in <code>%Fp<\/code> or <code>%Ns<\/code>. This behavior has been removed. If <code>%F<\/code> is encountered, it is now treated as the <code>%F<\/code> format specifier; if <code>%N<\/code> is encountered, it is now treated as an invalid parameter.<\/p>\n<\/li>\n<li>\n<p><strong>Infinity and NaN Formatting<\/strong>: In previous versions, infinities and NaNs would be formatted using a set of Visual C++-specific sentinel strings:<\/p>\n<ul>\n<li>Infinity: <code>1.#INF<\/code><\/li>\n<li>Quiet NaN: <code>1.#QNAN<\/code><\/li>\n<li>Signaling NaN: <code>1.#SNAN<\/code><\/li>\n<li>Indefinite NaN: <code>1.#IND<\/code><\/li>\n<\/ul>\n<p>Any of these may have been prefixed by a sign and may have been formatted slightly differently depending on field width and precision (sometimes with unusual effects, e.g. <code>printf(\"%.2f\\n\", INFINITY)<\/code> would print <code>1.#J<\/code> because the <code>#INF<\/code> would be &#8220;rounded&#8221; to a precision of 2 digits). C99 introduced new requirements on how infinities and NaNs are to be formatted. We have changed our implementation to conform to these new requirements. The new strings are as follows:<\/p>\n<ul>\n<li>Infinity: <code>inf<\/code><\/li>\n<li>Quiet NaN: <code>nan<\/code><\/li>\n<li>Signaling NaN: <code>nan(snan)<\/code><\/li>\n<li>Indefinite NaN:<code>nan(ind)<\/code><\/li>\n<\/ul>\n<p>Any of these may be prefixed by a sign. If a capital format specifier is used (e.g. <code>%F<\/code> instead of <code>%f<\/code>) then the strings are printed in capital letters (e.g. <code>INF<\/code> instead of <code>inf<\/code>), as is required (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806668\/printf-of-infinity-wrong\" target=\"_blank\">Connect #806668<\/a>).<\/p>\n<p>The <code>scanf<\/code> functions have been modified to parse these new strings, so these strings will round-trip through <code>printf<\/code> and <code>scanf<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Exponent Formatting<\/strong>: The <code>%e<\/code> and <code>%E<\/code> format specifiers format a floating point number as a decimal mantissa and exponent. The <code>%g<\/code> and <code>%G<\/code> format specifiers also format numbers in this form in some cases. In previous versions, the CRT would always generate strings with three-digit exponents. For example, <code>printf(\"%e\\n\", 1.0)<\/code> would print <code>1.000000e+000<\/code>. This was incorrect: C requires that if the exponent is representable using only one or two digits, then only two digits are to be printed.<\/p>\n<p>In Visual Studio 2005 a global conformance switch was added: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/0fatw238(v=vs.120).aspx\" target=\"_blank\"><code>_set_output_format<\/code><\/a>. A program could call this function with the argument <code>_TWO_DIGIT_EXPONENT<\/code>, to enable conforming exponent printing. This conformance switch has been removed and the default behavior has been changed to the standards-conforming exponent printing mode.<\/p>\n<\/li>\n<li>\n<p><strong><code>%A<\/code> and <code>%a<\/code> Zero Padding<\/strong>: The <code>%a<\/code> and <code>%A<\/code> format specifiers format a floating point number as a hexadecimal mantissa and binary exponent. In previous versions, the <code>printf<\/code> functions would incorrectly zero-pad strings. For example, <code>printf(\"%07.0a\\n\", 1.0)<\/code> would print <code>00x1p+0<\/code>, where it should print <code>0x01p+0<\/code>. This has been fixed.<\/p>\n<\/li>\n<li>\n<p><strong>Floating Point Formatting and Parsing Correctness<\/strong>: We have implemented new floating point formatting and parsing algorithms to improve correctness. This change affects the <code>printf<\/code> and <code>scanf<\/code> families of functions, as well as functions like <code>strtod<\/code>.<\/p>\n<p>The old formatting algorithms would generate only a limited number of digits, then would fill the remaining decimal places with zero. This is usually good enough to generate strings that will round-trip back to the original floating point value, but it&#8217;s not great if you want the exact value (or the closest decimal representation thereof). The new formatting algorithms generate as many digits as are required to represent the value (or to fill the specified precision). As an example of the improvement; consider the results when printing a large power of two:<\/p>\n<pre>    printf(\"%.0f\\n\", pow(2.0, 80))\n    Old:  1208925819614629200000000\n    New:  1208925819614629174706176<\/pre>\n<p>The old parsing algorithms would consider only up to 17 significant digits from the input string and would discard the rest of the digits. This is sufficient to generate a very close approximation of the value represented by the string, and the result is usually very close to the correctly rounded result. The new implementation considers all present digits and produces the correctly rounded result for all inputs (up to 768 digits in length). In addition, these functions now respect the rounding mode (controllable via <code>fesetround<\/code>).<\/p>\n<\/li>\n<li>\n<p><strong>Hexadecimal and Infinity\/NaN Floating Point Parsing<\/strong>: The floating point parsing algorithms will now parse hexadecimal floating point strings (such as those generated by the <code>%a<\/code> and <code>%A<\/code> <code>printf<\/code> format specifiers) and all infinity and NaN strings that are generated by the <code>printf<\/code> functions, as described above.<\/p>\n<\/li>\n<li>\n<p><strong><code>snprintf<\/code> and <code>vsnprintf<\/code> Are Now Implemented<\/strong>: The C99 <code>snprintf<\/code> and <code>vsnprintf<\/code> functions have been implemented.<\/p>\n<\/li>\n<li>\n<p><strong>Format String Validation<\/strong>: In previous versions, the <code>printf<\/code> and <code>scanf<\/code> functions would silently accept many invalid format strings, sometimes with unusual effects. For example, <code>%hlhlhld<\/code> would be treated as <code>%d<\/code>. All invalid format strings are now treated as invalid parameters.<\/p>\n<\/li>\n<li>\n<p><strong><code>fopen<\/code> Mode String Validation<\/strong>: In previous versions, the <code>fopen<\/code> family of functions silently accepted some invalid mode strings (e.g. <code>r+b+<\/code>). Invalid mode strings are now detected and treated as invalid parameters (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/792703\/invalid-mode-parameter-accepted-to-fopen\" target=\"_blank\">Connect #792703<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong><code>fseek<\/code> Use with Large Files<\/strong>: In previous versions, the <code>fseek<\/code> function was unable to seek to positions more than <code>INT_MAX<\/code> bytes from the beginning of a file. This has been fixed, but note that if you are working with large files, you <em>should<\/em> use the 64-bit I\/O functions like <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/75yw9bf3.aspx\" target=\"_blank\"><code>_fseeki64<\/code><\/a>. The <code>fseek<\/code> function can still only seek up to <code>INT_MAX<\/code> bytes forward at a time, as its offset parameter is of type <code>int<\/code> (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/810715\/fseek-cant-seek-to-locations-in-file-2gib\" target=\"_blank\">Connect #810715<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong><code>tmpnam<\/code> Generates Usable File Names<\/strong>: In previous versions, the <code>tmpnam<\/code> and <code>tmpnam_s<\/code> functions generated file names in the root of the drive (e.g. <code>\\sd3c.<\/code>). These functions now generate usable file name paths in a temporary directory.<\/p>\n<\/li>\n<li>\n<p><strong><code>FILE<\/code> Encapsulation<\/strong>: In previous versions, the <code>FILE<\/code> type was completely defined in <code>&lt;stdio.h&gt;<\/code>, so it was possible for user code to reach into a <code>FILE<\/code> and muck with its internals. We have refactored the stdio library to improve encapsulation of the library implementation details. As part of this, <code>FILE<\/code> as defined in <code>&lt;stdio.h&gt;<\/code> is now an opaque type and its members are inaccessible from outside of the CRT itself.<\/p>\n<\/li>\n<li>\n<p><strong><code>WEOF<\/code><\/strong>: The <code>WEOF<\/code> macro was improperly parenthesized, so expressions involving <code>WEOF<\/code> (e.g. <code>sizeof WEOF<\/code>) would not compile. This has been fixed (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/806655\/sizeof-weof-will-not-compile\" target=\"_blank\">Connect #806655<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong>Unusable Port I\/O Functions are Removed<\/strong>: Six functions have been removed from the CRT: <code>_inp<\/code>, <code>_inpw<\/code>, <code>_inpd<\/code>, <code>_outp<\/code>, <code>_outpw<\/code>, and <code>_outpd<\/code>. These functions were used for reading from and writing to I\/O ports on x86; because they used privileged instructions, they have never worked in user-mode code on Windows NT-based operating systems.<\/p>\n<\/li>\n<li>\n<p><strong>Standard File Descriptor and Stream Initialization: &nbsp;<\/strong>The initialization of the standard file descriptors and streams has been fixed for non-console apps. &nbsp;In non-console programs, the file handles are initialized to -2 (<a title=\"Connect #785119\" href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/785119\/fileno-stdin-0-for-non-console-application\">Connect #785119<\/a>).<\/p>\n<\/li>\n<\/ul>\n<h3>&lt;stdlib.h&gt;, &lt;malloc.h&gt;, and &lt;sys\/stat.h&gt;<\/h3>\n<ul>\n<li>\n<p><strong><code>strtod<\/code> Et Al.<\/strong>: The <code>strtod<\/code> family of functions would return an incorrect end pointer via the out parameter if the number at the beginning of the input string was composed of more than 2<sup>32<\/sup>-1 characters. This has been fixed.<\/p>\n<\/li>\n<li>\n<p><strong><code>strtof<\/code> and <code>wcstof<\/code><\/strong>: The <code>strtof<\/code> and <code>wcstof<\/code> functions failed to set <code>errno<\/code> to <code>ERANGE<\/code> when the value was not representable as a <code>float<\/code>. This has been fixed. (Note that this error was specific to these two functions; the <code>strtod<\/code>, <code>wcstod<\/code>, <code>strtold<\/code>, and <code>wcstold<\/code> functions were unaffected.)<\/p>\n<\/li>\n<li>\n<p><strong><code>_stat<\/code> Functions<\/strong>: In previous versions, the <code>_stat<\/code> functions might read one character past the end of the path string. This has been fixed (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/796796\/msvcrt-stat-actually-stat64i32-blindly-refers-to-2nd-char-of-string-parameter\" target=\"_blank\">Connect #796796<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong>Aligned Allocation Functions<\/strong>: In previous versions, the aligned allocation functions (<code>_aligned_malloc<\/code>, <code>_aligned_offset_malloc<\/code>, etc.) would silently accept requests for a block with an alignment of <code>0<\/code>. The documentation requires that the requested alignment be a power of two, which zero is not. This has been fixed, and a requested alignment of <code>0<\/code> is now treated as an invalid parameter (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/809604\/aligned-malloc-should-fail-with-align-0\" target=\"_blank\">Connect #809604<\/a>).<\/p>\n<\/li>\n<li>\n<p>The <code>_heapadd<\/code>, <code>_heapset<\/code>, and <code>_heapused<\/code> functions have been removed. These functions have been nonfunctional since the CRT was updated to use the Windows heap.<\/p>\n<\/li>\n<li>\n<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms235330.aspx\" target=\"_blank\">smalheap<\/a> link option has been removed.<\/p>\n<\/li>\n<\/ul>\n<h3>&lt;time.h&gt;<\/h3>\n<ul>\n<li>\n<p><strong><code>clock<\/code><\/strong>: In previous versions, the <code>clock<\/code> function was implemented using the Windows API <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms724397.aspx\" target=\"_blank\"><code>GetSystemTimeAsFileTime<\/code><\/a>. With this implementation, the <code>clock<\/code> function was sensitive to the system time, and was thus not necessarily monotonic. The <code>clock<\/code> function has been reimplemented in terms of <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms644904.aspx\" target=\"_blank\"><code>QueryPerformanceCounter<\/code><\/a> and is now monotonic.<\/p>\n<p>Several customers have noted that as specified by C, the <code>clock<\/code> function should return the &#8220;processor time used&#8221; by the process, not the wall clock time elapsed since the process was started. We continue to implement <code>clock<\/code> as returning wall clock time elapsed, as there is a substantial amount of software written for Windows that expects this behavior.<\/p>\n<\/li>\n<li>\n<p><strong><code>fstat<\/code> and <code>_utime<\/code><\/strong>: In previous versions, the <code>_stat<\/code>, <code>fstat<\/code>, and <code>_utime<\/code> functions handle daylight savings time incorrectly. Prior to Visual Studio 2013, all of these functions had a subtle daylight savings time bug: during daylight time, they incorrectly adjusted standard time times as if they were in daylight time. It appears that this went unnoticed for many years because while the implementations were incorrect, they were all consistently incorrect.<\/p>\n<p>In Visual Studio 2013, the bug in the <code>_stat<\/code> family of functions was fixed, but the similar bugs in the <code>fstat<\/code> and <code>_utime<\/code> families of functions were not fixed. This exposed the issue in those functions, because they started handling daylight savings time differently from the <code>_stat<\/code> functions. The <code>fstat<\/code> and <code>_utime<\/code> families of functions have now been fixed, so all of these functions now handle daylight savings time correctly and consistently (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/811534\/utime-sometimes-fails-to-set-the-correct-file-times-in-visual-c-2013\" target=\"_blank\">Connect #811534<\/a>).<\/p>\n<\/li>\n<li>\n<p><strong><code>asctime<\/code><\/strong>: In previous versions, the <code>asctime<\/code> function would pad single-digit days with a leading zero, e.g. <code>Fri Jun 06 08:00:00 2014<\/code>. The specification requires that such days be padded with a leading space, e.g. <code>Fri Jun _6 08:00:00 2014<\/code> (I&#8217;ve used an underscore the mark the padding space). This has been fixed.<\/p>\n<\/li>\n<li>\n<p><strong><code>time<\/code> and <code>ftime<\/code><\/strong>: The <code>time<\/code> and <code>ftime<\/code> functions will now use the <code>GetSystemTimePreciseAsFileTime<\/code> when that API is available (Windows 8 and above) for improved precision.<\/p>\n<\/li>\n<li>\n<p><strong><code>strftime<\/code> and <code>wcsftime<\/code><\/strong>: The <code>strftime<\/code> and <code>wcsftime<\/code> functions now support the <code>%C<\/code>, <code>%D<\/code>, <code>%e<\/code>, <code>%F<\/code>, <code>%g<\/code>, <code>%G<\/code>, <code>%h<\/code>, <code>%n<\/code>, <code>%r<\/code>, <code>%R<\/code>, <code>%t<\/code>, <code>%T<\/code>, <code>%u<\/code>, and <code>%V<\/code> format specifiers. Additionally, the <code>E<\/code> and <code>O<\/code> modifiers are parsed but ignored.<\/p>\n<p>The <code>%c<\/code> format specifier is specified as producing an &#8220;appropriate date and time representation&#8221; for the current locale. In the C locale, this representation is required to be the same as <code>%a %b %e %T %Y<\/code>. This is the same form as is produced by <code>asctime<\/code>. In previous versions, the <code>%c<\/code> format specifier incorrectly formatted times using a <code>MM\/DD\/YY HH:MM:SS<\/code> representation. This has been fixed.<\/p>\n<\/li>\n<li>\n<p><strong>C11 <code>timespec<\/code> and <code>timespec_get<\/code><\/strong>: <code>&lt;time.h&gt;<\/code> now defines the C11 <code>timespec<\/code> type and the <code>timespec_get<\/code> function. In addition, the <code>TIME_UTC<\/code> macro, for use with the <code>timespec_get<\/code> function, is now defined.<\/p>\n<\/li>\n<li>\n<p><strong><code>CLOCKS_PER_SEC<\/code><\/strong>: The <code>CLOCKS_PER_SEC<\/code> macro now expands to an integer of type <code>clock_t<\/code>, as required by C.<\/p>\n<\/li>\n<\/ul>\n<h3>operator new T[N]<\/h3>\n<ul>\n<li>In previous versions, <code>operator new T[N]<\/code> would fail to call constructors for elements in array if <code>N<\/code> was greater than 2<sup>32<\/sup>-1. This has been fixed (<a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/802400\/constructors-do-not-run-for-objects-in-arrays-with-more-than-max-int-elements\" target=\"_blank\">Connect #802400<\/a>).<\/li>\n<\/ul>\n<div>James McNellis (james.mcnellis@microsoft.com<span>)<\/span><br \/>Senior Software Development Engineer, Visual C++ Libraries<\/div>\n","protected":false},"excerpt":{"rendered":"<p>(This is the second of two articles on changes to the C Runtime (CRT) in the Visual Studio &#8220;14&#8221; CTP. The first article, The Great C Runtime (CRT) Refactoring, covered the major architectural changes to the CRT; this second article enumerates the new features, bug fixes, and breaking changes.) This list covers all of the [&hellip;]<\/p>\n","protected":false},"author":282,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>(This is the second of two articles on changes to the C Runtime (CRT) in the Visual Studio &#8220;14&#8221; CTP. The first article, The Great C Runtime (CRT) Refactoring, covered the major architectural changes to the CRT; this second article enumerates the new features, bug fixes, and breaking changes.) This list covers all of the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/282"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=523"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/523\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}