Description
Type of issue
Missing information
Description
I'm working on the ECMA C# spec for V9's function pointers.
Consider the following code fragment:
public static void Log() { ... }
delegate*<void> fp = &Log; // pointer to managed function Log()
fp(); // OK; call Log() via function pointer
(*fp)(); // Error; CS0193, "The * or -> operator must be applied to a pointer"
When fp
is a function pointer in C/C++, both of the final 2 statements are allowed and are equivalent, so I tried both in C#.
However, in C#, a function pointer cannot be dereferenced, and that is why the second call is rejected.
Perhaps the simplest fix is to change (preferably in the compiler, but at least in the docs)
CS0193: The * or -> operator must be applied to a pointer
to
CS0193: The * or -> operator must be applied to a data pointer
which then excludes function pointers and void pointers.
And then add
A function pointer cannot be dereferenced.
BTW, I note that attempting to dereference a void pointer results in CS0242, "The operation in question is undefined on void pointers", so that need not be mentioned here.
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0193?f1url=%3FappId%3Droslyn%26k%3Dk(CS0193)
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0193.md
Document Version Independent Id
43bae4fc-fe3e-033d-8f16-e8bffaebf202
Platform Id
adbc4b45-657e-029c-fd2e-d875421f318b
Article author
Metadata
- ID: 6f680362-c4bd-95d6-2cad-99e77e847cd0
- PlatformId: adbc4b45-657e-029c-fd2e-d875421f318b
- Service: dotnet-csharp
- Sub-service: errors-warnings
Metadata
Metadata
Assignees
Type
Projects
Status