From 52624f54c0ad99a4d659fe4e2560a472be795c49 Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Thu, 9 Apr 2020 14:33:18 -0700 Subject: [PATCH] Update function pointers proposal for binary operators. (#3348) * Update function pointers proposal for binary operators. * Update wording per feedback. --- proposals/function-pointers.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/proposals/function-pointers.md b/proposals/function-pointers.md index f4340cab96..aaba9c3592 100644 --- a/proposals/function-pointers.md +++ b/proposals/function-pointers.md @@ -212,6 +212,29 @@ Restrictions of this feature: deliberately not specified by the language. This includes whether they are static vs. instance or exactly what signature they are emitted with. + +### Operators on Function Pointer Types + +The section in unsafe code on operators is modified as such: + +> In an unsafe context, several constructs are available for operating on all _pointer\_type_s that are not _funcptr\_type_s: +> +> * The `*` operator may be used to perform pointer indirection ([Pointer indirection](unsafe-code.md#pointer-indirection)). +> * The `->` operator may be used to access a member of a struct through a pointer ([Pointer member access](unsafe-code.md#pointer-member-access)). +> * The `[]` operator may be used to index a pointer ([Pointer element access](unsafe-code.md#pointer-element-access)). +> * The `&` operator may be used to obtain the address of a variable ([The address-of operator](unsafe-code.md#the-address-of-operator)). +> * The `++` and `--` operators may be used to increment and decrement pointers ([Pointer increment and decrement](unsafe-code.md#pointer-increment-and-decrement)). +> * The `+` and `-` operators may be used to perform pointer arithmetic ([Pointer arithmetic](unsafe-code.md#pointer-arithmetic)). +> * The `==`, `!=`, `<`, `>`, `<=`, and `=>` operators may be used to compare pointers ([Pointer comparison](unsafe-code.md#pointer-comparison)). +> * The `stackalloc` operator may be used to allocate memory from the call stack ([Fixed size buffers](unsafe-code.md#fixed-size-buffers)). +> * 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)) +> * The `==`, `!=`, `<`, `>`, `<=`, and `=>` operators may be used to compare pointers ([Pointer comparison](unsafe-code.md#pointer-comparison)). + +Additionally, we modify all the sections in `Pointers in expressions` to forbid function pointer types, except `Pointer comparison` and `The sizeof operator`. + ### Better function member The better function member specification will be changed to include the following line: