Things that make writing a clean binding system more difficult

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 28 13:16:11 PDT 2016


On Thursday, July 28, 2016 01:49:35 Walter Bright via Digitalmars-d wrote:
> On 7/28/2016 1:33 AM, Ethan Watson wrote:
> > 1) Declaring a function pointer with a ref return value can't be done
> > without workarounds.
> >
> > Try compiling this:
> >
> > ref int function( int, int ) functionPointer;
> >
> > It won't let you, because only parameters and for loop symbols can be ref
> > types. Despite the fact that I intend the function pointer to be of a
> > kind that returns a ref int, I can't declare that easily. Easy, declare
> > an alias, right?
> >
> > alias RefFunctionPointer = ref int function( int, int );
>
> C/C++ have essentially the same problem, if you want to declare a function
> pointer parameter that has different linkage.
>
> The trouble is there's an ambiguity in the grammar. I don't really have
> anything better than the two step process you outlined.

Well, if we decided to make parens with ref legal, then we could make it
work. e.g.

ref(int) function(int, int) functionPointer;

Now, I don't know of any other case where you'd actually use parens with ref
if it were legal, but it would solve this particular case if we wanted to
provide a way around the ambiguity.

- Jonathan M Davis



More information about the Digitalmars-d mailing list