Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function pointers proposal for binary operators. #3348

Merged
merged 2 commits into from
Apr 9, 2020

Conversation

333fred
Copy link
Member

@333fred 333fred commented Apr 9, 2020

This forbids all binary operators except comparison operators.

proposals/function-pointers.md Outdated Show resolved Hide resolved
proposals/function-pointers.md Outdated Show resolved Hide resolved
@333fred
Copy link
Member Author

333fred commented Apr 9, 2020

@gafter addressed feedback.

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@333fred 333fred merged commit 52624f5 into dotnet:master Apr 9, 2020
@333fred 333fred deleted the func-ptr-binary-ops branch April 9, 2020 21:33
>
> In an unsafe context, several constructs are available for operating on all _funcptr\_type_s:
> * The `&` operator may be used to obtain the address of static methods ([Allow address-of to target methods](function-pointers.md#allow-address-of-to-target-methods))
> * The `==`, `!=`, `<`, `>`, `<=`, and `=>` operators may be used to compare pointers ([Pointer comparison](unsafe-code.md#pointer-comparison)).
Copy link
Member

Choose a reason for hiding this comment

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

<, >, <=, and => do not make sense for function pointers. I know that C/C++ allows it, but it is not necessarily a good prior art to follow.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish we could block them, but they're defined on void*, and function pointers are implicitly convertible.

Copy link
Member

@jkotas jkotas Apr 21, 2020

Choose a reason for hiding this comment

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

== and != are questionable too. Function pointers in .NET are not stable. For example, ldftn on same function can return two different pointer values in two places in the program. It does actually happen in practice, e.g. a typical example is ldftn M before M was executed for the first time and after M was executed for the first time.

Copy link
Member

Choose a reason for hiding this comment

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

Always emit a warning when any of these are used on function pointers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that's interesting. Seems like a good candidate for a warning then. I'll add a note to the tracking issue.

> * The `fixed` statement may be used to temporarily fix a variable so its address can be obtained ([The fixed statement](unsafe-code.md#the-fixed-statement)).
>
> In an unsafe context, several constructs are available for operating on all _funcptr\_type_s:
> * The `&` operator may be used to obtain the address of static methods ([Allow address-of to target methods](function-pointers.md#allow-address-of-to-target-methods))
Copy link
Member

Choose a reason for hiding this comment

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

This not operating on funcptr type (contrary to what the previous line says).

Should this rather say that The& operator may be used to obtain the address of a variable ?

ie. should the following be possible?

delegate*<int> p1 = ...;
var x = &p1;

Copy link
Member Author

Choose a reason for hiding this comment

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

You can certainly do that, just like you can do that for any local. The operating on is taken from existing examples for pointer types.

Copy link
Member

Choose a reason for hiding this comment

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

You can certainly do that, just like you can do that for any local.

Good, it is what I have expected.

The formatting of this section makes it sound like that it is not possible. Taking address of a local is explicitly mentioned in the pointers that are not function pointers section above; but it is not mentioned in this section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants