Condividi tramite


Compiler Warning (level 1) C4996 

Error Message

'function': was declared deprecated

The compiler encountered a function that was marked with deprecated. The function may no longer be supported in a future release. You can turn this warning off with the warning pragma (example below).

C4996 is generated for the line on which the function is declared and for the line on which the function is used.

You will see C4996 if you are using members of the <hash_map> and <hash_set> header files in the std namespace. See The stdext Namespace for more information.

Some CRT functions have been deprecated in favor of new, more secure functions. For more information on deprecated CRT functions, see Security Enhancements in the CRT.

C4996 can also occur if you use MFC or ATL functions that were deprecated for security reasons. To suppress these warnings, see _AFX_SECURE_NO_DEPRECATE and _ATL_SECURE_NO_DEPRECATE.

Example

The following sample generates C4996.

// C4996.cpp
// compile with: /W1
// C4996 warning expected
#include <stdio.h>

// #pragma warning(disable : 4996)
void func1(void) {
   printf_s("\nIn func1");
}

__declspec(deprecated) void func1(int) {
   printf_s("\nIn func2");
}

int main() {
   func1();
   func1(1);
}

C4996 can also occur if you do not use a checked iterator when compiling with _SECURE_SCL 1. See Checked Iterators for more information.

The following sample generates C4996.

// C4996_b.cpp
// compile with: /EHsc /W1
#define _SECURE_SCL 1
#include <algorithm>
using namespace std;
using namespace stdext;
int main() {
   int a [] = {1, 2, 3};
   int b [] = {10, 11, 12};
   copy(a, a + 3, b);   // C4996
   copy(a, a + 3, checked_array_iterator<int *>(b, 3));   // OK
}