We have a C ++ library. We provide user affirmations and disclaimers from Posix NDEBUGand assert(story below).
The statement looks like this on Windows:
if (!(exp)) { \
std::ostringstream oss; \
oss << "Assertion failed: " << (char*)(__FILE__) << "(" \
<< (int)(__LINE__) << "): " << (char*)(__FUNCTION__) \
<< std::endl; \
std::cerr << oss.str(); \
DebugBreak(); \
} \
}
The task that we have is that we must include <windows.h>, and this leads to a lot of extra steepness, even with WIN32_LEAN_AND_MEAN. Some additional cracks, such as minand max, break compilation in C ++. In fact, testing our changes has broken us.
<windows.h> " ", . extern void WINAPI DebugBreak(void); Microsoft docs DebugBreak, - .
NO_MIN_MAX ( , ) , , . , . #include .
#pragma push_macro #pragma pop_macro , Microsoft V++ 6.0. VS2003.
- <windows.h>. DebugBreak Windows.h?
.
:
#include <algorithm>
#define MY_ASSERT(exp) { \
if (!(exp)) { \
DebugBreak(); \
} \
}
void dummy(int x1, int x2)
{
MY_ASSERT(x1 == std::min(x1, x2));
}
extern. Windows 8.1 x64 VS2012 VS2013. .
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
assert.cpp
assert.cpp(11) : warning C4273: 'DebugBreak' : inconsistent dll linkage
C:\Program Files (x86)\Windows Kits\8.1\include\um\debugapi.h(70) : see
previous definition of 'DebugBreak'
assert.cpp(21) : error C2589: '(' : illegal token on right side of '::'
assert.cpp(21) : error C2059: syntax error : '::'
assert.cpp(21) : error C2143: syntax error : missing ';' before '{'
<debugapi.h>, :
WINBASEAPI
VOID
WINAPI
DebugBreak(
VOID
);
WINBASEAPI . , .
- ++, CVE-2016-7420. - , . , ( ); (Apple CrashReporter, Ubuntu Apport, Microsoft Windows Error Reporting, ..).
/ , Makefile Visual Studio . / , ++ throw() . /, .
, , , " / -DNDEBUG" . ; RTFM , . , CMake , Autotools , Eclipse .. , CVE. , , , .