From 63b411f0b73b37782d280697c7a5bb597a901553 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 May 2025 06:59:12 +0000 Subject: [PATCH 1/4] Initial plan for issue From 0335a66df0ed886ca883db4e891702b467f84573 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 May 2025 07:02:55 +0000 Subject: [PATCH 2/4] Update CS0193 error message documentation for function pointers Co-authored-by: yufeih <511355+yufeih@users.noreply.github.com> --- docs/csharp/misc/cs0193.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/csharp/misc/cs0193.md b/docs/csharp/misc/cs0193.md index 40d5db085dcbf..d50d12af1fe75 100644 --- a/docs/csharp/misc/cs0193.md +++ b/docs/csharp/misc/cs0193.md @@ -1,7 +1,7 @@ --- description: "Compiler Error CS0193" title: "Compiler Error CS0193" -ms.date: 07/20/2015 +ms.date: 05/27/2023 f1_keywords: - "CS0193" helpviewer_keywords: @@ -10,9 +10,9 @@ ms.assetid: 7b60fd99-9eee-4d61-ad75-585a16e22e96 --- # Compiler Error CS0193 -The \* or -> operator must be applied to a pointer +The \* or -> operator must be applied to a data pointer -The \* or -> operator was used with a nonpointer type. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types). +The \* or -> operator was used with a nonpointer type or with a function pointer. Function pointers cannot be dereferenced in C#. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types). The following sample generates CS0193: @@ -45,3 +45,19 @@ public class MyClass } } ``` + +The following example shows that function pointers cannot be dereferenced in C#, unlike in C/C++: + +```csharp +unsafe class FunctionPointerExample +{ + public static void Log() { /* ... */ } + + public static void Example() + { + delegate* fp = &Log; // pointer to managed function Log() + fp(); // OK; call Log() via function pointer + (*fp)(); // Error; CS0193, function pointers cannot be dereferenced + } +} +``` From 10058e11c54479eca5915ca1167a48873e3fdc92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 May 2025 07:03:48 +0000 Subject: [PATCH 3/4] Refine CS0193 documentation with additional unsafe context and links Co-authored-by: yufeih <511355+yufeih@users.noreply.github.com> --- docs/csharp/misc/cs0193.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/misc/cs0193.md b/docs/csharp/misc/cs0193.md index d50d12af1fe75..465d623de7d05 100644 --- a/docs/csharp/misc/cs0193.md +++ b/docs/csharp/misc/cs0193.md @@ -12,7 +12,7 @@ ms.assetid: 7b60fd99-9eee-4d61-ad75-585a16e22e96 The \* or -> operator must be applied to a data pointer -The \* or -> operator was used with a nonpointer type or with a function pointer. Function pointers cannot be dereferenced in C#. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types). +The \* or -> operator was used with a nonpointer type or with a function pointer. Function pointers cannot be dereferenced in C#. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types) and [Function pointers](../language-reference/unsafe-code.md#function-pointers). The following sample generates CS0193: @@ -53,7 +53,7 @@ unsafe class FunctionPointerExample { public static void Log() { /* ... */ } - public static void Example() + public static unsafe void Example() { delegate* fp = &Log; // pointer to managed function Log() fp(); // OK; call Log() via function pointer From 957ce08594cbe79c5c30d5c2c51a4b205c0278ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 May 2025 13:51:07 +0000 Subject: [PATCH 4/4] Update ms.date to 05/27/2025 as requested Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/csharp/misc/cs0193.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/misc/cs0193.md b/docs/csharp/misc/cs0193.md index 465d623de7d05..dcc7673c4ba1d 100644 --- a/docs/csharp/misc/cs0193.md +++ b/docs/csharp/misc/cs0193.md @@ -1,7 +1,7 @@ --- description: "Compiler Error CS0193" title: "Compiler Error CS0193" -ms.date: 05/27/2023 +ms.date: 05/27/2025 f1_keywords: - "CS0193" helpviewer_keywords: