Skip to content

Repo sync for protected CLA branch #3640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/build/reference/nmake-function-patsubst.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $(patsubst %lo,Bye,Hello Hey Hi) # Evaluates to "Bye Hey Hi"
# A wildcard can be used in the pattern without a wildcard in the replacement

$(patsubst he%,_%_,Hello Hey Hi) # Evaluates to "Hello Hey Hi" - patsubst is case-sensitive, so no substitutions performed
$(patsubst he%,_%_,Hello Hey Hi) # Evaluates to "_llo_ _y_ Hi" - patsubsti is case-insensitive
$(patsubsti he%,_%_,Hello Hey Hi) # Evaluates to "_llo_ _y_ Hi" - patsubsti is case-insensitive

# patsubsti is commonly used to change the file extensions of a list of files
OBJ_FILES=$(patsubst %.c,%.obj,$(C_SOURCES)) $(patsubst %.cpp,%.obj,$(patsubst %.cxx,%.obj,$(CPP_SOURCES)))
Expand Down
25 changes: 12 additions & 13 deletions docs/c-runtime-library/reference/alloca.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
description: "Learn more about: _alloca"
title: "_alloca"
ms.date: "11/04/2016"
ms.date: 01/05/2022
api_name: ["_alloca"]
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll"]
api_type: ["DLLExport"]
topic_type: ["apiref"]
f1_keywords: ["_alloca", "alloca"]
helpviewer_keywords: ["memory allocation, stack", "alloca function", "_alloca function"]
ms.assetid: 74488eb1-b71f-4515-88e1-cdd03b6f8225
---
# `_alloca`

Expand All @@ -24,20 +23,20 @@ void *_alloca(

### Parameters

*`size`*<br/>
*`size`*\
Bytes to be allocated from the stack.

## Return Value

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.

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).
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).

## Remarks

**`_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).

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:
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:

- Windows NT SEH exception filter expression: `__except ( _alloca() )`

Expand All @@ -50,7 +49,7 @@ However, **`_alloca`** can be called directly from within an EH routine or from
> [!IMPORTANT]
> In Windows XP, if **`_alloca`** is called inside a try/catch block, you must call [`_resetstkoflw`](resetstkoflw.md) in the catch block.

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).
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).

## Requirements

Expand Down Expand Up @@ -103,7 +102,7 @@ int main()

// If the stack overflows, use this function to restore.
errcode = _resetstkoflw();
if (errcode)
if (errcode == 0) // _resetstkoflw() returns 0 on failure
{
printf_s("Could not reset the stack!\n");
_exit(1);
Expand All @@ -118,9 +117,9 @@ Allocated 1000 bytes of stack at 0x0012FB50

## See also

[Memory Allocation](../../c-runtime-library/memory-allocation.md)<br/>
[`calloc`](calloc.md)<br/>
[`malloc`](malloc.md)<br/>
[`realloc`](realloc.md)<br/>
[`_resetstkoflw`](resetstkoflw.md)<br/>
[`_malloca`](malloca.md)<br/>
[Memory Allocation](../../c-runtime-library/memory-allocation.md)\
[`calloc`](calloc.md)\
[`malloc`](malloc.md)\
[`realloc`](realloc.md)\
[`_resetstkoflw`](resetstkoflw.md)\
[`_malloca`](malloca.md)
2 changes: 1 addition & 1 deletion docs/cpp/new-operator-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The **`new`** operator can't be used to allocate a function, but it can be used

```cpp
int (**p) () = new (int (*[7]) ());
delete *p;
delete p;
```

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.
Expand Down
Loading