- Created: 2016-05-08
I propose the universal star *
operator.
It works for all pointer related operations.
*x # pointer to variable/argument (address of)
x* # dereference pointer
*int # pointer to type
We need a basic set of syntax defined in order to present more in depth proposals to the language.
Pointer handling seems inevitable in a compiled language.
I propose the following syntax.
- A star in front of something is read as "pointer to".
- A star behind something is read as "dereference".
The first rule works in type expressions and everything that an address can be taken of. For example: variables, arguments, functions and instance members.
The second rule only applies to expressions which evaluate to pointers.
These two rules are minimal and very consistent. That should make it very easy to teach.
Some more examples:
fn f (x) -> bool; # declare a function f
def pf = *f # pointer to function f
pf*(n) # invocation of the function behind the pointer
type i5 = *(5 of int) # pointer to array
type p5 = 5 of *int # array of pointers
It does not make much sense to multiply a pointer with something. So this ambiguity should be easily resolvable.
It's unclear for the reader wether a function pointer is dereferenced or the function result is dereferenced.
To mitigate the problem it should be illigal to dereference a function result without brackets around the function.
var a = f()* # function returns a pointer that is dereferenced
Endless other syntaxes are thinkable. If we find one more pleasing or conflict with other ideas, we should adapt it.
Nothing so far.