Skip to content
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
12 changes: 9 additions & 3 deletions docs/csharp/language-reference/unsafe-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Unsafe code has the following properties:
- Using unsafe code introduces security and stability risks.
- The code that contains unsafe blocks must be compiled with the [**AllowUnsafeBlocks**](compiler-options/language.md#allowunsafeblocks) compiler option.

For information about best practices for unsafe code in C#, see [Unsafe code best practices](../../standard/unsafe-code/best-practices.md).

## Pointer types

In an unsafe context, a type can be a pointer type, in addition to a value type, or a reference type. A pointer type declaration takes one of the following forms:
Expand Down Expand Up @@ -148,8 +150,8 @@ internal struct Buffer

Fixed-size buffers differ from regular arrays in the following ways:

- May only be used in an `unsafe` context.
- May only be instance fields of structs.
- Can only be used in an `unsafe` context.
- Can only be instance fields of structs.
- They're always vectors, or one-dimensional arrays.
- The declaration should include the length, such as `fixed char id[8]`. You can't use `fixed char id[]`.

Expand Down Expand Up @@ -179,7 +181,7 @@ The preceding code illustrates several of the rules on the function accessed as

- Function pointers can only be declared in an `unsafe` context.
- Methods that take a `delegate*` (or return a `delegate*`) can only be called in an `unsafe` context.
- The `&` operator to obtain the address of a function is allowed only on `static` functions. (This rule applies to both member functions and local functions).
- The `&` operator to obtain the address of a function is allowed only on `static` functions. (This rule applies to both member functions and local functions.)

The syntax has parallels with declaring `delegate` types and using pointers. The `*` suffix on `delegate` indicates the declaration is a *function pointer*. The `&` when assigning a method group to a function pointer indicates the operation takes the address of the method.

Expand All @@ -192,3 +194,7 @@ You can learn more about function pointers in the [Function pointer](~/_csharpla
## C# language specification

For more information, see the [Unsafe code](~/_csharpstandard/standard/unsafe-code.md) chapter of the [C# language specification](~/_csharpstandard/standard/README.md).

## See also

- [Unsafe code best practices](../../standard/unsafe-code/best-practices.md)
Loading