ref:https://msdn.microsoft.com/ko-kr/library/ttcz0bys.aspx
컴파일러 경고 (수준 3) C4996
C4996
로 표시 된 변수 또는 함수는 컴파일러에서 발생 하는 경우에 발생 사용 되지 않는합니다.
/D_CRT_NONSTDC_NO_WARNINGS
_CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS
줄을 추가합니다.
-
MFC 또는 ATL 코드의 다양 한 메시지
C4996
이 발생할 수 있습니다.
CLR 코드의 오류 마샬링
C4996
은 마샬링 라이브러리를 사용할 때 발생할 수 있습니다.
C&4996;이 생성 하는 예제
C4996
은 함수를 선언한 줄과 사용한 줄에서 발생합니다.
// C4996.cpp // compile with: /W3 // 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은 _ITERATOR_DEBUG_LEVEL
를 정의한 상태에서(디버그 모드 빌드의 경우 기본적으로 1로 설정) 컴파일할 때 확인된 반복기를 사용하지 않는 경우에 발생할 수 있습니다.
// C4996_b.cpp // compile with: /EHsc /W3 /c #define _ITERATOR_DEBUG_LEVEL 1 #include <algorithm> #include <iterator> using namespace std; using namespace stdext; int main() { int a[] = { 1, 2, 3 }; int b[] = { 10, 11, 12 }; copy(a, a + 3, b + 1); // C4996 // try the following line instead // copy(a, a + 3, b); copy(a, a + 3, checked_array_iterator<int *>(b, 3)); // OK }
#include <algorithm> #include <array> #include <iostream> #include <iterator> #include <numeric> #include <string> #include <vector> using namespace std; template <typename C> void print(const string& s, const C& c) { cout << s; for (const auto& e : c) { cout << e << " "; } cout << endl; } int main() { vector<int> v(16); iota(v.begin(), v.end(), 0); print("v: ", v); // OK: vector::iterator is checked in debug mode // (i.e. an overrun will trigger a debug assertion) vector<int> v2(16); transform(v.begin(), v.end(), v2.begin(), [](int n) { return n * 2; }); print("v2: ", v2); // OK: back_insert_iterator is marked as checked in debug mode // (i.e. an overrun is impossible) vector<int> v3; transform(v.begin(), v.end(), back_inserter(v3), [](int n) { return n * 3; }); print("v3: ", v3); // OK: array::iterator is checked in debug mode // (i.e. an overrun will trigger a debug assertion) array<int, 16> a4; transform(v.begin(), v.end(), a4.begin(), [](int n) { return n * 4; }); print("a4: ", a4); // OK: Raw arrays are checked in debug mode // (i.e. an overrun will trigger a debug assertion) // NOTE: This applies only when raw arrays are given to STL algorithms! int a5[16]; transform(v.begin(), v.end(), a5, [](int n) { return n * 5; }); print("a5: ", a5); // WARNING C4996: Pointers cannot be checked in debug mode // (i.e. an overrun will trigger undefined behavior) int a6[16]; int * p6 = a6; transform(v.begin(), v.end(), p6, [](int n) { return n * 6; }); print("a6: ", a6); // OK: stdext::checked_array_iterator is checked in debug mode // (i.e. an overrun will trigger a debug assertion) int a7[16]; int * p7 = a7; transform(v.begin(), v.end(), stdext::make_checked_array_iterator(p7, 16), [](int n) { return n * 7; }); print("a7: ", a7); // WARNING SILENCED: stdext::unchecked_array_iterator is marked as checked in debug mode // (i.e. it performs no checking, so an overrun will trigger undefined behavior) int a8[16]; int * p8 = a8; transform(v.begin(), v.end(), stdext::make_unchecked_array_iterator(p8), [](int n) { return n * 8; }); print("a8: ", a8); }
마샬링 라이브러리에 System::String
const char *
로 변환하는 컨텍스트가 필요하기 때문에 다음 샘플에서는 C4996 경고가 생성됩니다.
// C4996_Marshal.cpp // compile with: /clr // C4996 expected #include <stdlib.h> #include <string.h> #include <msclr\marshal.h> using namespace System; using namespace msclr::interop; int main() { String^ message = gcnew String("Test String to Marshal"); const char* result; result = marshal_as<const char*>( message ); return 0; }
'Programming > C,C++' 카테고리의 다른 글
STL vector, list, map [펌] (0) | 2017.03.24 |
---|---|
echo server/client (0) | 2017.03.24 |
FFMPEG 빌드 해보기 (0) | 2017.03.22 |
simple avi parser (0) | 2017.03.21 |
WinApi BMP Viewer by SetPixel (0) | 2017.03.21 |