Skip to content

Conversation

Copy link
Contributor

Copilot AI commented May 27, 2025

This PR updates the documentation for compiler error CS0193 to provide more clarity regarding function pointers.

The changes:

  • Modified the error message to specify "data pointer" instead of just "pointer" to clarify that function pointers are excluded
  • Added an explanation that function pointers cannot be dereferenced in C#, unlike in C/C++
  • Included a code example demonstrating the error when attempting to dereference a function pointer
  • Added a reference to the function pointers documentation

These changes address confusion for developers who are familiar with C/C++ where dereferencing function pointers is valid syntax.

Example of the issue:

unsafe class Example
{
    public static void Log() { }
    
    public static unsafe void Main()
    {
        delegate*<void> fp = &Log;   // pointer to managed function Log()
        fp();                        // OK; call Log() via function pointer
        (*fp)();                     // Error; CS0193, function pointers cannot be dereferenced
    }
}

Fixes #46398.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/misc/cs0193.md Compiler Error CS0193

Copilot AI changed the title [WIP] Message CS0193 is misleading in the context of a function pointer Update CS0193 error message documentation for function pointers May 27, 2025
Copilot AI requested a review from yufeih May 27, 2025 07:04
Copilot finished work on behalf of yufeih May 27, 2025 07:04
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @copilot

Once you fix the date, this is ready to merge.

Copy link
Contributor Author

Copilot AI commented May 27, 2025

Hi @copilot

Once you fix the date, this is ready to merge.

I've updated the ms.date field to 05/27/2025 as requested in commit 957ce08.

Copilot finished work on behalf of BillWagner May 27, 2025 13:52
@BillWagner BillWagner marked this pull request as ready for review May 27, 2025 13:57
@BillWagner BillWagner requested a review from a team as a code owner May 27, 2025 13:57
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @copilot

and @yufeih

This LGTM, and I'll :shipit: now.

@BillWagner BillWagner enabled auto-merge (squash) May 27, 2025 13:58
@BillWagner BillWagner merged commit eb52a69 into main May 27, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-46398 branch May 27, 2025 14:07
BillWagner added a commit that referenced this pull request May 29, 2025
#46423 was written by copilot. Add the associated metadata for ai-assisted articles.
@BillWagner BillWagner mentioned this pull request May 29, 2025
BillWagner added a commit that referenced this pull request May 29, 2025
#46423 was written by copilot. Add the associated metadata for ai-assisted articles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message CS0193 is misleading in the context of a function pointer

3 participants