Skip to content

Commit 102cfd9

Browse files
authored
Merge pull request #2984 from corob-msft/docs/corob/cpp-docs2301
Attempt i18n fixes for C4996
2 parents 450353a + b33bac0 commit 102cfd9

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

docs/error-messages/compiler-warnings/compiler-warning-level-3-c4996.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Compiler Warning (level 3) C4996"
33
description: "Explains why Compiler warning C4996 happens, and describes what to do about it."
4-
ms.date: "11/25/2019"
4+
ms.date: 07/09/2020
55
f1_keywords: ["C4996"]
66
helpviewer_keywords: ["C4996"]
77
ms.assetid: 926c7cc2-921d-43ed-ae75-634f560dd317
88
---
99
# Compiler Warning (level 3) C4996
1010

11-
Your code uses a function, class member, variable, or typedef that's marked *deprecated*. Symbols are deprecated by using a [__declspec(deprecated)](../../cpp/deprecated-cpp.md) modifier, or the C++14 [\[\[deprecated\]\]](../../cpp/attributes.md) attribute. The actual C4996 warning message is specified by the `deprecated` modifier or attribute of the declaration.
11+
Your code uses a function, class member, variable, or typedef that's marked *deprecated*. Symbols are deprecated by using a [`__declspec(deprecated)`](../../cpp/deprecated-cpp.md) modifier, or the C++14 [`[[deprecated]]`](../../cpp/attributes.md) attribute. The actual C4996 warning message is specified by the `deprecated` modifier or attribute of the declaration.
1212

1313
> [!IMPORTANT]
1414
> This warning is always a deliberate message from the author of the header file that declares the symbol. Don't use the deprecated symbol without understanding the consequences.
@@ -21,19 +21,29 @@ Many functions, member functions, template functions, and global variables in Vi
2121

2222
To fix a C4996 issue, we usually recommend you change your code. Use the suggested functions and global variables instead. If you need to use the existing functions or variables for portability reasons, you can turn off the warning.
2323

24-
To turn off the warning for a specific line of code, use the [warning](../../preprocessor/warning.md) pragma, `#pragma warning(suppress : 4996)`.
24+
### Turn off the warning for a specific line of code
2525

26-
To turn off the warning within a file, use the warning pragma, `#pragma warning(disable : 4996)`.
26+
To turn off the warning for a specific line of code, use the [`warning`](../../preprocessor/warning.md) pragma, `#pragma warning(suppress : 4996)`.
2727

28-
To turn off the warning globally in command-line builds, use the [/wd4996](../../build/reference/compiler-option-warning-level.md) command-line option.
28+
### Turn off the warning within a file
29+
30+
To turn off the warning within a file for everything that follows, use the warning pragma, `#pragma warning(disable : 4996)`.
31+
32+
### Turn off the warning in command-line builds
33+
34+
To turn off the warning globally in command-line builds, use the [`/wd4996`](../../build/reference/compiler-option-warning-level.md) command-line option.
35+
36+
### Turn off the warning for a project in Visual Studio
2937

3038
To turn off the warning for an entire project in the Visual Studio IDE:
3139

3240
1. Open the **Property Pages** dialog for your project. For information on how to use the Property Pages dialog, see [Property Pages](../../build/reference/property-pages-visual-cpp.md).
3341

34-
1. Select the **Configuration Properties** > **C/C++** > **Advanced** page.
42+
1. Select the **Configuration Properties** > **C/C++** > **Advanced** property page.
43+
44+
1. Edit the **Disable Specific Warnings** property to add *`4996`*. Choose **OK** to apply your changes.
3545

36-
1. Edit the **Disable Specific Warnings** property to add `4996`. Choose **OK** to apply your changes.
46+
### Disable the warning using preprocessor macros
3747

3848
You can also use preprocessor macros to turn off certain specific classes of deprecation warnings used in the libraries. These macros are described below.
3949

@@ -51,33 +61,33 @@ Here are some of the common sources of C4996 warnings and errors:
5161

5262
## POSIX function names
5363

54-
**The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name:** *new-name*. **See online help for details.**
64+
**`The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name:`** _`new-name.`_ **`See online help for details.`**
5565

5666
Microsoft renamed some POSIX and Microsoft-specific library functions in the CRT to conform with C99 and C++03 constraints on reserved and global implementation-defined names. *Only the names are deprecated, not the functions themselves*. In most cases, a leading underscore was added to the function name to create a conforming name. The compiler issues a deprecation warning for the original function name, and suggests the preferred name.
5767

5868
To fix this issue, we usually recommend you change your code to use the suggested function names instead. However, the updated names are Microsoft-specific. If you need to use the existing function names for portability reasons, you can turn off these warnings. The functions are still available in the library under their original names.
5969

60-
To turn off deprecation warnings for these functions, define the preprocessor macro **\_CRT\_NONSTDC\_NO\_WARNINGS**. You can define this macro at the command line by including the option `/D_CRT_NONSTDC_NO_WARNINGS`.
70+
To turn off deprecation warnings for these functions, define the preprocessor macro **`_CRT_NONSTDC_NO_WARNINGS`**. You can define this macro at the command line by including the option `/D_CRT_NONSTDC_NO_WARNINGS`.
6171

6272
## Unsafe CRT Library functions
6373

64-
**This function or variable may be unsafe. Consider using** *safe-version* **instead. To disable deprecation, use \_CRT\_SECURE\_NO\_WARNINGS. See online help for details.**
74+
**`This function or variable may be unsafe. Consider using`** _`safe-version`_ **`instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.`**
6575

6676
Microsoft deprecated some CRT and C++ Standard Library functions and globals because more secure versions are available. Most of the deprecated functions allow unchecked read or write access to buffers. Their misuse can lead to serious security issues. The compiler issues a deprecation warning for these functions, and suggests the preferred function.
6777

68-
To fix this issue, we recommend you use the function or variable *safe-version* instead. Sometimes you can't, for portability or backwards compatibility reasons. Carefully verify it's not possible for a buffer overwrite or overread to occur in your code. Then, you can turn off the warning.
78+
To fix this issue, we recommend you use the function or variable *`safe-version`* instead. Sometimes you can't, for portability or backwards compatibility reasons. Carefully verify it's not possible for a buffer overwrite or overread to occur in your code. Then, you can turn off the warning.
6979

70-
To turn off deprecation warnings for these functions in the CRT, define **\_CRT\_SECURE\_NO\_WARNINGS**.
80+
To turn off deprecation warnings for these functions in the CRT, define **`_CRT_SECURE_NO_WARNINGS`**.
7181

72-
To turn off warnings about deprecated global variables, define **\_CRT\_SECURE\_NO\_WARNINGS\_GLOBALS**.
82+
To turn off warnings about deprecated global variables, define **`_CRT_SECURE_NO_WARNINGS_GLOBALS`**.
7383

7484
For more information about these deprecated functions and globals, see [Security Features in the CRT](../../c-runtime-library/security-features-in-the-crt.md) and [Safe Libraries: C++ Standard Library](../../standard-library/safe-libraries-cpp-standard-library.md).
7585

7686
## Unsafe Standard Library functions
7787

78-
__'std::__*function_name*__::\_Unchecked\_iterators::\_Deprecate' Call to std::__*function_name* **with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D\_SCL\_SECURE\_NO\_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'**
88+
**`'std::`** *`function_name`* **`::_Unchecked_iterators::_Deprecate' Call to std::`** *`function_name`* **`with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'`**
7989

80-
This warning appears in debug builds because certain C++ Standard Library template functions don't check parameters for correctness. Often it's because not enough information is available to the function to check container bounds. Or, because iterators may be used incorrectly with the function. This warning helps you identify these functions, because they may be a source of serious security holes in your program. For more information, see [Checked iterators](../../standard-library/checked-iterators.md).
90+
In Visual Studio 2015, this warning appears in debug builds because certain C++ Standard Library template functions don't check parameters for correctness. Often it's because not enough information is available to the function to check container bounds. Or, because iterators may be used incorrectly with the function. This warning helps you identify these functions, because they may be a source of serious security holes in your program. For more information, see [Checked iterators](../../standard-library/checked-iterators.md).
8191

8292
For example, this warning appears in Debug mode if you pass an element pointer to `std::copy`, instead of a plain array. To fix this issue, use an appropriately declared array, so the library can check the array extents and do bounds checking.
8393

@@ -200,7 +210,7 @@ int main()
200210
}
201211
```
202212
203-
If you've verified that your code can't have a buffer-overrun error, you can turn off this warning. To turn off warnings for these functions, define **\_SCL\_SECURE\_NO\_WARNINGS**.
213+
If you've verified that your code can't have a buffer-overrun error, you can turn off this warning. To turn off warnings for these functions, define **`_SCL_SECURE_NO_WARNINGS`**.
204214
205215
## Checked iterators enabled
206216
@@ -232,21 +242,21 @@ C4996 can occur if you use MFC or ATL functions that were deprecated for securit
232242

233243
To fix this issue, we strongly recommend you change your code to use updated functions instead.
234244

235-
For information on how to suppress these warnings, see [_AFX_SECURE_NO_WARNINGS](../../mfc/reference/diagnostic-services.md#afx_secure_no_warnings).
245+
For information on how to suppress these warnings, see [`_AFX_SECURE_NO_WARNINGS`](../../mfc/reference/diagnostic-services.md#afx_secure_no_warnings).
236246

237247
## Obsolete CRT functions and variables
238248

239-
**This function or variable has been superseded by newer library or operating system functionality. Consider using** *new_item* **instead. See online help for details.**
249+
**`This function or variable has been superseded by newer library or operating system functionality. Consider using`** *`new_item`* **`instead. See online help for details.`**
240250

241251
Some library functions and global variables are deprecated as obsolete. These functions and variables may be removed in a future version of the library. The compiler issues a deprecation warning for these items, and suggests the preferred alternative.
242252

243253
To fix this issue, we recommend you change your code to use the suggested function or variable.
244254

245-
To turn off deprecation warnings for these items, define **\_CRT\_OBSOLETE\_NO\_WARNINGS**. For more information, see the documentation for the deprecated function or variable.
255+
To turn off deprecation warnings for these items, define **`_CRT_OBSOLETE_NO_WARNINGS`**. For more information, see the documentation for the deprecated function or variable.
246256

247257
## Marshaling errors in CLR code
248258

249-
C4996 can also occur when you use the CLR marshaling library. In this case, C4996 is an error, not a warning. The error occurs when you use [marshal_as](../../dotnet/marshal-as.md) to convert between two data types that require a [marshal_context Class](../../dotnet/marshal-context-class.md). You can also receive this error when the marshaling library doesn't support a conversion. For more information about the marshaling library, see [Overview of marshaling in C++](../../dotnet/overview-of-marshaling-in-cpp.md).
259+
C4996 can also occur when you use the CLR marshaling library. In this case, C4996 is an error, not a warning. The error occurs when you use [`marshal_as`](../../dotnet/marshal-as.md) to convert between two data types that require a [`marshal_context` Class](../../dotnet/marshal-context-class.md). You can also receive this error when the marshaling library doesn't support a conversion. For more information about the marshaling library, see [Overview of marshaling in C++](../../dotnet/overview-of-marshaling-in-cpp.md).
250260

251261
This example generates C4996 because the marshaling library requires a context to convert from a `System::String` to a `const char *`.
252262

@@ -271,7 +281,7 @@ int main() {
271281
272282
## Example: User-defined deprecated function
273283
274-
You can use the deprecated attribute in your own code to warn callers when you no longer recommend use of certain functions. In this example, C4996 is generated in two places: One for the line the deprecated function is declared on, and one for the line where the function is used.
284+
You can use the `deprecated` attribute in your own code to warn callers when you no longer recommend use of certain functions. In this example, C4996 is generated in two places: One for the line the deprecated function is declared on, and one for the line where the function is used.
275285
276286
```cpp
277287
// C4996.cpp

0 commit comments

Comments
 (0)