Skip to content

Add note about _CRT_DECLARE_NONSTDC_NAMES #3658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2022

Conversation

eldakesh-ms
Copy link
Contributor

With /c11 and /c17 properly defining __STDC__, users may encounter that the POSIX functions they are relying on are no longer exposed. This was always the case with /Za but is now also visible with the standard C versions.

Gated by 17.2 preview 2 at the earliest.

With `/c11` and `/c17` properly defining `__STDC__`, users may encounter that the POSIX functions they are relying on are no longer exposed. This was always the case with `/Za` but is now also visible with the standard C versions.
@PRMerger17
Copy link
Contributor

@eldakesh-ms : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@PRMerger4
Copy link
Contributor

@corob-msft : Thanks for your contribution! The author(s) have been notified to review your proposed change.

Copy link
Contributor

@colin-home colin-home left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eldakesh-ms Looks like a useful addition. Thanks!

@colin-home colin-home merged commit 1111e57 into MicrosoftDocs:main Jan 19, 2022
@colin-home
Copy link
Contributor

Oops, I missed the part about 17.2. We'll fix it in post. Although I note the flag has been around a long time and already guarded the POSIX typedefs and defined macros.

Also, we recommend Microsoft people use the private repo, cpp-docs-pr, for their contributions, since it does additional build validations and also lets us embargo content for release.

@@ -20,7 +20,7 @@ The UCRT also implements a large subset of the POSIX.1 (ISO/IEC 9945-1:1996, the

Functions specific to the Microsoft implementation of Visual C++ are found in the vcruntime library. Many of these functions are for internal use and can't be called by user code. Some are documented for use in debugging and implementation compatibility.

The C++ standard reserves names that begin with an underscore in the global namespace to the implementation. Both the POSIX functions and Microsoft-specific runtime library functions are in the global namespace, but aren't part of the standard C runtime library. That's why the preferred Microsoft implementations of these functions have a leading underscore. For portability, the UCRT also supports the default names, but the Microsoft C++ compiler issues a deprecation warning when code that uses them is compiled. Only the default names are deprecated, not the functions themselves. To suppress the warning, define `_CRT_NONSTDC_NO_WARNINGS` before including any headers in code that uses the original POSIX names.
The C++ standard reserves names that begin with an underscore in the global namespace to the implementation. Both the POSIX functions and Microsoft-specific runtime library functions are in the global namespace, but aren't part of the standard C runtime library. That's why the preferred Microsoft implementations of these functions have a leading underscore. For portability, the UCRT also supports the default names, but the Microsoft C++ compiler issues a deprecation warning when code that uses them is compiled. Only the default names are deprecated, not the functions themselves. To suppress the warning, define `_CRT_NONSTDC_NO_WARNINGS` before including any headers in code that uses the original POSIX names. Because the C standard doesn't allow non-standard names in header files, by default [`/std:c11`](../build/reference/std-specify-language-standard-version.md) and [`/std:c17`](../build/reference/std-specify-language-standard-version.md) don't expose the default names for POSIX functions, types, and macros. If these names are necessary, define `_CRT_DECLARE_NONSTDC_NAMES` to expose them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these names are necessary, define _CRT_DECLARE_NONSTDC_NAMES to expose them.

This is actually an on/off switch. Defining that macro to 1 will enable the default names and defining that macro to 0 will disable the default names, regardless of the /std or /Za setting.

Xazax-hun pushed a commit to Xazax-hun/cpp-docs that referenced this pull request Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants