|
| 1 | +--- |
| 2 | +description: "Learn more about: hybrid_patchable (C++)" |
| 3 | +title: "hybrid_patchable (C++)" |
| 4 | +ms.date: 1/15/2025 |
| 5 | +f1_keywords: ["hybrid_patchable"] |
| 6 | +helpviewer_keywords: ["__declspec keyword [C++], hybrid_patchable", "hybrid_patchable __declspec keyword"] |
| 7 | +--- |
| 8 | +# `hybrid_patchable` (C++) |
| 9 | + |
| 10 | +**Microsoft Specific** |
| 11 | + |
| 12 | +Use **`__declspec(hybrid_patchable)`** extended attribute which can be used in the declaration of functions. |
| 13 | + |
| 14 | +## Syntax |
| 15 | + |
| 16 | +> `__declspec(hybrid_patchable)` |
| 17 | +
|
| 18 | +## Remarks |
| 19 | + |
| 20 | +We recommend that all new code use the [`noexcept`](noexcept-cpp.md) operator rather than `__declspec(nothrow)`. |
| 21 | + |
| 22 | +This attribute tells the compiler that the declared function and the functions it calls never throw an exception. However, it does not enforce the directive. In other words, it never causes [`std::terminate`](../standard-library/exception-functions.md#terminate) to be invoked, unlike **`noexcept`**, or in **`std:c++17`** mode (Visual Studio 2017 version 15.5 and later), `throw()`. |
| 23 | + |
| 24 | +With the synchronous exception handling model, now the default, the compiler can eliminate the mechanics of tracking the lifetime of certain unwindable objects in such a function, and significantly reduce the code size. Given the following preprocessor directive, the three function declarations below are equivalent in **`/std:c++14`** mode: |
| 25 | + |
| 26 | +```cpp |
| 27 | +__declspec(hybrid_patchable) int Example() { |
| 28 | + return 1; |
| 29 | +} |
| 30 | +``` |
| 31 | +
|
| 32 | +Generates the following fast-forward sequence: |
| 33 | +
|
| 34 | +``` |
| 35 | +EXP+#Example: |
| 36 | + 00000001400CE000: 48 8B C4 mov rax,rsp |
| 37 | + 00000001400CE003: 48 89 58 20 mov qword ptr [rax+20h],rbx |
| 38 | + 00000001400CE007: 55 push rbp |
| 39 | + 00000001400CE008: 5D pop rbp |
| 40 | + 00000001400CE009: E9 BA 7A F3 FF jmp #Example |
| 41 | + 00000001400CE00E: CC int 3 |
| 42 | + 00000001400CE00F: CC int 3 |
| 43 | +``` |
| 44 | +
|
| 45 | +
|
| 46 | +In **`/std:c++17`** mode, `throw()` is not equivalent to the others that use `__declspec(nothrow)` because it causes `std::terminate` to be invoked if an exception is thrown from the function. |
| 47 | +
|
| 48 | +The `void __stdcall f3() throw();` declaration uses the syntax defined by the C++ standard. In C++17 the `throw()` keyword was deprecated. |
| 49 | +
|
| 50 | +**END Microsoft Specific** |
| 51 | +
|
| 52 | +## See also |
| 53 | +
|
| 54 | +[`__declspec`](../cpp/declspec.md)\ |
| 55 | +[`noexcept`](noexcept-cpp.md)\ |
| 56 | +[Keywords](../cpp/keywords-cpp.md) |
0 commit comments