Things that make writing a clean binding system more difficult

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 28 21:44:16 PDT 2016


On 28.07.2016 10:49, Walter Bright 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.
> ...

My parser accepts the following:

int function(int,int)ref functionPointer;

I wasn't really aware that this was illegal in DMD. (Other function 
attributes, such as pure, are accepted.)

In fact, even the following is disallowed:
int foo(int)ref{}


Should I file an enhancement request?


More information about the Digitalmars-d mailing list