Skip to content
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

Fix the return type of stackalloc #888

Merged
merged 3 commits into from
Aug 15, 2023
Merged
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
4 changes: 3 additions & 1 deletion standard/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,9 @@ When a *stackalloc_initializer* is present:

Each *stackalloc_element_initializer* shall have an implicit conversion to *unmanaged_type* ([§10.2](conversions.md#102-implicit-conversions)). The *stackalloc_element_initializer*s initialize elements in the allocated memory in increasing order, starting with the element at index zero. In the absence of a *stackalloc_initializer*, the content of the newly allocated memory is undefined.

The result of a *stackalloc_expression* is a pointer of type `T *` ([§23.9](unsafe-code.md#239-stack-allocation)), where `T` is the *unmanaged_type*, which is implicitly converted to `Span<T>` in safe code.
The result of a *stackalloc_expression* is an instance of type `Span<T>`, where `T` is the *unmanaged_type* and the instance’s `Length` property returns the number of items allocated.
Nigel-Ecma marked this conversation as resolved.
Show resolved Hide resolved

> *Note*: When occurring in unsafe code the result of a *stackalloc_expression* may be of a different type, see ([§23.9](unsafe-code.md#239-stack-allocation)). *end note*

Access via an instance of `Span<T>` to the elements of an allocated block is range checked.

Expand Down