From 4421469ee00df51ac2ef4cc1d05df673d1441b95 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Sat, 7 Mar 2026 12:21:46 -0500 Subject: [PATCH 1/6] Support Numeric IntPtr Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/unsafe-code.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/standard/unsafe-code.md b/standard/unsafe-code.md index a69ee7d52..fa46c276e 100644 --- a/standard/unsafe-code.md +++ b/standard/unsafe-code.md @@ -787,14 +787,20 @@ In an unsafe context, the `+` operator ([§12.13.5](expressions.md#12135-additio ```csharp T* operator +(T* x, int y); T* operator +(T* x, uint y); +T* operator +(T* x, nint y); +T* operator +(T* x, nuint y); T* operator +(T* x, long y); T* operator +(T* x, ulong y); T* operator +(int x, T* y); T* operator +(uint x, T* y); +T* operator +(nint x, T* y); +T* operator +(nuint x, T* y); T* operator +(long x, T* y); T* operator +(ulong x, T* y); T* operator –(T* x, int y); T* operator –(T* x, uint y); +T* operator -(T* x, nint y); +T* operator -(T* x, nuint y); T* operator –(T* x, long y); T* operator –(T* x, ulong y); long operator –(T* x, T* y); @@ -802,7 +808,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)`. From e91a96efabe98aab7c39ebf8648a4ddf997c450b Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Sat, 7 Mar 2026 12:35:54 -0500 Subject: [PATCH 2/6] Support Numeric IntPtr Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/expressions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/standard/expressions.md b/standard/expressions.md index 142e87ff6..12ea55f80 100644 --- a/standard/expressions.md +++ b/standard/expressions.md @@ -287,6 +287,8 @@ As an example of numeric promotion, consider the predefined implementations of t ```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); From 4a69bb076480a0116c1e96703a9e3eefd038f89f Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Sat, 7 Mar 2026 12:37:19 -0500 Subject: [PATCH 3/6] Support Numeric IntPtr Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/conversions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/standard/conversions.md b/standard/conversions.md index a329b449c..29239c310 100644 --- a/standard/conversions.md +++ b/standard/conversions.md @@ -119,6 +119,8 @@ In most cases, an identity conversion has no effect at runtime. However, since f There is an identity conversion between `nint` and `System.IntPtr`, and between `nuint` and `System.UIntPtr`. +For the compound types array, nullable type, constructed type, and tuple, there is an identity conversion between native integers ([§8.3.6](types.md#836-integral-types)) and their underlying types. + ### 10.2.3 Implicit numeric conversions The implicit numeric conversions are: From 5ac8a0040094ca05d1dbd651c1b690cb0bc398e5 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Sat, 7 Mar 2026 12:48:16 -0500 Subject: [PATCH 4/6] Support Numeric IntPtr Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/types.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/standard/types.md b/standard/types.md index 5e158def1..962bf274a 100644 --- a/standard/types.md +++ b/standard/types.md @@ -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** ----------- | ------------------ @@ -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` @@ -338,7 +338,7 @@ 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. +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: > From c3971a9c3b1153ad3b64bf49ffad807757173fdb Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 4 May 2026 13:55:35 -0400 Subject: [PATCH 5/6] Remove outdated HTML comment This is V 11, so remove this HTML Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e --- standard/types.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/standard/types.md b/standard/types.md index 962bf274a..deeca5a2c 100644 --- a/standard/types.md +++ b/standard/types.md @@ -362,14 +362,6 @@ Every simple type has members. Each simple type has its aliased struct type’s > > *end note*. - - -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: From fc99c5c4804de0060ce0f37c37a773dccdd1b61c Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 17 Nov 2026 15:31:59 -0500 Subject: [PATCH 6/6] Additional IntPtr requirements. --- standard/conversions.md | 2 -- standard/types.md | 2 ++ standard/unsafe-code.md | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/standard/conversions.md b/standard/conversions.md index 29239c310..a329b449c 100644 --- a/standard/conversions.md +++ b/standard/conversions.md @@ -119,8 +119,6 @@ In most cases, an identity conversion has no effect at runtime. However, since f There is an identity conversion between `nint` and `System.IntPtr`, and between `nuint` and `System.UIntPtr`. -For the compound types array, nullable type, constructed type, and tuple, there is an identity conversion between native integers ([§8.3.6](types.md#836-integral-types)) and their underlying types. - ### 10.2.3 Implicit numeric conversions The implicit numeric conversions are: diff --git a/standard/types.md b/standard/types.md index deeca5a2c..a39407e25 100644 --- a/standard/types.md +++ b/standard/types.md @@ -338,6 +338,8 @@ The simple types are aliases for predefined `struct` types in the `System` names `bool` | `System.Boolean` `decimal` | `System.Decimal` +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: diff --git a/standard/unsafe-code.md b/standard/unsafe-code.md index fa46c276e..353dba7a8 100644 --- a/standard/unsafe-code.md +++ b/standard/unsafe-code.md @@ -787,20 +787,14 @@ In an unsafe context, the `+` operator ([§12.13.5](expressions.md#12135-additio ```csharp T* operator +(T* x, int y); T* operator +(T* x, uint y); -T* operator +(T* x, nint y); -T* operator +(T* x, nuint y); T* operator +(T* x, long y); T* operator +(T* x, ulong y); T* operator +(int x, T* y); T* operator +(uint x, T* y); -T* operator +(nint x, T* y); -T* operator +(nuint x, T* y); T* operator +(long x, T* y); T* operator +(ulong x, T* y); T* operator –(T* x, int y); T* operator –(T* x, uint y); -T* operator -(T* x, nint y); -T* operator -(T* x, nuint y); T* operator –(T* x, long y); T* operator –(T* x, ulong y); long operator –(T* x, T* y);