Skip to content
Draft
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: 2 additions & 0 deletions standard/expressions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 12 Expressions

Check warning on line 2 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 84 > maximum 83; : null_conditional_member_access null_forgiving_operator? '(' argument_list? ')'
## 12.1 General

An expression is a sequence of operators and operands. This clause defines the syntax, order of evaluation of operands and operators, and meaning of expressions.
Expand All @@ -15,7 +15,7 @@

### 12.2.1 General

The result of an expression is classified as one of the following:

Check warning on line 18 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 99 > maximum 83; Console.WriteLine(formattable.ToString(System.Globalization.CultureInfo.InvariantCulture));

- A value. Every value has an associated type.
- A variable. Unless otherwise specified, a variable is explicitly typed and has an associated type, namely the declared type of the variable. An implicitly typed variable has no associated type.
Expand Down Expand Up @@ -287,6 +287,8 @@
```csharp
int operator *(int x, int y);
uint operator *(uint x, uint y);
nint operator *(nint x, nint y);
nuint operator *(nuint x, nuint y);
long operator *(long x, long y);
ulong operator *(ulong x, ulong y);
float operator *(float x, float y);
Expand Down
18 changes: 6 additions & 12 deletions standard/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ A struct type is a value type that can declare constants, fields, methods, prope

### 8.3.5 Simple types

Except for `nint` and `nuint`, the simple types are aliases for predefined `struct` types in the `System` namespace, as described in the table below.
The simple types are aliases for predefined `struct` types in the `System` namespace, as described in the table below.

**Keyword** | **Aliased type**
----------- | ------------------
Expand All @@ -328,8 +328,8 @@ Except for `nint` and `nuint`, the simple types are aliases for predefined `stru
`ushort` | `System.UInt16`
`int` | `System.Int32`
`uint` | `System.UInt32`
`nint` | none; see below
`nuint` | none; see below
`nint` | `System.IntPtr`
`nuint` | `System.UIntPtr`
`long` | `System.Int64`
`ulong` | `System.UInt64`
`char` | `System.Char`
Expand All @@ -338,7 +338,9 @@ Except for `nint` and `nuint`, the simple types are aliases for predefined `stru
`bool` | `System.Boolean`
`decimal` | `System.Decimal`

Every simple type has members. Each simple type that is an alias for a predefined struct type, has that struct type’s members.
An implementation shall support the predefined conversions and operators specified for `nint` and `nuint` on their aliased types.

Every simple type has members. Each simple type has its aliased struct type’s members.

> *Example*: `int` has any implementation-specific members declared in `System.Int32` and the members (required and implementation specific) inherited from `System.Object`, and the following statements are permitted:
>
Expand All @@ -362,14 +364,6 @@ Every simple type has members. Each simple type that is an alias for a predefine
>
> *end note*.

<!-- C# 11: In C# 11, nint and nuint become true aliases for System.IntPtr and System.UIntPtr. The following paragraphs describing the non-alias relationship should be updated or removed. -->

The types `nint` and `nuint` are represented by the types `System.IntPtr` and `System.UIntPtr`, respectively, and are *not* aliases for these types. In this context being *represented by* means:

- The only members directly accessible for `nint` and `nuint` are the required methods of `Object` ([§C.2](standard-library.md#c2-standard-library-types-defined-in-isoiec-23271)). Any other members of `System.IntPtr` and `System.UIntPtr` may be accessed by explicit conversion to those types.
- Operations performed through `dynamic` binding on `System.IntPtr` and `System.UIntPtr` values do not have access to the `nint` and `nuint` operators.
- In all other respects `nint` and `nuint` behave as if they are aliases of `System.IntPtr` and `System.UIntPtr`.

### 8.3.6 Integral types

C# supports the following integral types, with the sizes and value ranges, as shown:
Expand Down
2 changes: 1 addition & 1 deletion standard/unsafe-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ long operator –(T* x, T* y);

There are no predefined operators for pointer addition or subtraction with native integer ([§8.3.6](types.md#836-integral-types)) offsets. Instead, `nint` and `nuint` values shall be promoted to `long` and `ulong`, respectively, with pointer arithmetic using the predefined operators for those types.

Given an expression `P` of a data pointer type `T*` and an expression `N` of type `int`, `uint`, `long`, or `ulong`, the expressions `P + N` and `N + P` compute the pointer value of type `T*` that results from adding `N * sizeof(T)` to the address given by `P`. Likewise, the expression `P – N` computes the pointer value of type `T*` that results from subtracting `N * sizeof(T)` from the address given by `P`.
Given an expression `P` of a data pointer type `T*` and an expression `N` of type `int`, `uint`, `nint`, `nuint`, `long`, or `ulong`, the expressions `P + N` and `N + P` compute the pointer value of type `T*` that results from adding `N * sizeof(T)` to the address given by `P`. Likewise, the expression `P – N` computes the pointer value of type `T*` that results from subtracting `N * sizeof(T)` from the address given by `P`.

Given two expressions, `P` and `Q`, of a data pointer type `T*`, the expression `P – Q` computes the difference between the addresses given by `P` and `Q` and then divides that difference by `sizeof(T)`. The type of the result is always `long`. In effect, `P - Q` is computed as `((long)(P) - (long)(Q)) / sizeof(T)`.

Expand Down
Loading