Страница:
Error handling helpers internals
Страницы
Ad hoc range helpers
Bitwise operation helpers
CppWinRT authoring helpers
Error handling customization
Error handling helpers internals
Error handling helpers
Error logging and observation
Event handles
Exception policy
File System Helpers (filesystem.h)
Home
Internals Local data
Kernel events
Kernel spin locks
Last error preservation
Lock guard object
Macro meta programming
Mutex handles
Parameter handling helpers
RAII resource wrapper details
RAII resource wrappers
RPC helpers
Re entrant locks
Reader writer locks
Registry Helpers
Secure data erasure
Semaphore handles
Shutdown aware objects
Slim events
String helpers
Template metaprogramming helpers
Token Helpers
Type validation helpers
WDF resource classes
WIL and CppWinRT together
Waiting on kernel objects
Win32 helpers
WinRT and COM wrappers internals
WinRT and COM wrappers
Windowing helpers
Windows Runtime helpers
safe_cast
string_maker
2
Error handling helpers internals
Raymond Chen редактировал(а) эту страницу 2021-04-13 19:08:36 -07:00
Содержание
This page describes implementation details of the WIL error handling helpers. Apps should not rely on these details, because they are subject to change. The details are documented here to assist with debugging and to assist people who are implementing WIL itself.
Return macros
The return macros generally expand to
__WI_SUPPRESS_4127_S
do {
...
if (some_condition(...)) {
__RETURN_SOMETHING(...);
}
} __WI_SUPPRESS_4127_E while ((void)0, 0)
- The
do { ... } while (0)
pattern is a standard pattern for avoiding issues with statement-like macros. - The condition in the
while()
iswhile ((void)0, 0)
to attempt to avoid "conditional expression is constant" warnings. The comma operator prevents the controlling expression from being a constant expression (per the C++ language rules) and therefore avoids the compiler warning. __WI_SUPPRESS_4127_S
temporarily suppresses warning 4127: Conditional expression is constant.__WI_SUPPRESS_4127_E
restores the previous state of warning 4127.
The body of the do
loop is performed with warning 4127 suppressed because
the some_condition(...)
may, after compiler optimization, turn into
a constant that is always true or always false.
- The
__RETURN_SOMETHING(...)
is itself another macro that performs logging before eventually executing areturn (something)
.