You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **`_alloca`** routine returns a **`void`** pointer to the allocated space, which is guaranteed to be suitably aligned for storage of any type of object. If *`size`* is 0, **`_alloca`** allocates a zero-length item and returns a valid pointer to that item.
33
32
34
-
A stack overflow exception is generated if the space cannot be allocated. The stack overflow exception is not a C++ exception; it is a structured exception. Instead of using C++ exception handling, you must use [Structured Exception Handling](../../cpp/structured-exception-handling-c-cpp.md) (SEH).
33
+
A stack overflow exception is generated if the space can't be allocated. The stack overflow exception isn't a C++ exception; it's a structured exception. Instead of using C++ exception handling, you must use [Structured Exception Handling](../../cpp/structured-exception-handling-c-cpp.md) (SEH).
35
34
36
35
## Remarks
37
36
38
37
**`_alloca`** allocates *`size`* bytes from the program stack. The allocated space is automatically freed when the calling function exits (not when the allocation merely passes out of scope). Therefore, do not pass the pointer value returned by **`_alloca`** as an argument to [`free`](free.md).
39
38
40
-
There are restrictions to explicitly calling **`_alloca`** in an exception handler (EH). EH routines that run on x86-class processors operate in their own memory frame: They perform their tasks in memory space that is not based on the current location of the stack pointer of the enclosing function. The most common implementations include Windows NT structured exception handling (SEH) and C++ catch clause expressions. Therefore, explicitly calling **`_alloca`** in any of the following scenarios results in program failure during the return to the calling EH routine:
39
+
There are restrictions to explicitly calling **`_alloca`** in an exception handler (EH). EH routines that run on x86-class processors operate in their own memory frame: They perform their tasks in memory space that isn't based on the current location of the stack pointer of the enclosing function. The most common implementations include Windows NT structured exception handling (SEH) and C++ catch clause expressions. Therefore, explicitly calling **`_alloca`** in any of the following scenarios results in program failure during the return to the calling EH routine:
41
40
42
41
- Windows NT SEH exception filter expression: `__except ( _alloca() )`
43
42
@@ -50,7 +49,7 @@ However, **`_alloca`** can be called directly from within an EH routine or from
50
49
> [!IMPORTANT]
51
50
> In Windows XP, if **`_alloca`** is called inside a try/catch block, you must call [`_resetstkoflw`](resetstkoflw.md) in the catch block.
52
51
53
-
In addition to the above restrictions, when using the[`/clr` (Common Language Runtime Compilation)](../../build/reference/clr-common-language-runtime-compilation.md) option, **`_alloca`**cannot be used in **`__except`** blocks. For more information, see [`/clr` Restrictions](../../build/reference/clr-restrictions.md).
52
+
In addition to the above restrictions, when using the[`/clr` (Common Language Runtime Compilation)](../../build/reference/clr-common-language-runtime-compilation.md) option, **`_alloca`**can't be used in **`__except`** blocks. For more information, see [`/clr` Restrictions](../../build/reference/clr-restrictions.md).
54
53
55
54
## Requirements
56
55
@@ -103,7 +102,7 @@ int main()
103
102
104
103
// If the stack overflows, use this function to restore.
105
104
errcode = _resetstkoflw();
106
-
if (errcode)
105
+
if (errcode == 0) // _resetstkoflw() returns 0 on failure
107
106
{
108
107
printf_s("Could not reset the stack!\n");
109
108
_exit(1);
@@ -118,9 +117,9 @@ Allocated 1000 bytes of stack at 0x0012FB50
Copy file name to clipboardExpand all lines: docs/cpp/new-operator-cpp.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ The **`new`** operator can't be used to allocate a function, but it can be used
65
65
66
66
```cpp
67
67
int (**p) () = new (int (*[7]) ());
68
-
delete*p;
68
+
delete p;
69
69
```
70
70
71
71
If you use the operator **`new`** without any extra arguments, and compile with the [`/GX`](../build/reference/gx-enable-exception-handling.md), [`/EHa`](../build/reference/eh-exception-handling-model.md), or [`/EHs`](../build/reference/eh-exception-handling-model.md) option, the compiler generates code to call operator **`delete`** if the constructor throws an exception.
0 commit comments