May 05, 2012
On 5 May 2012 02:38, Jonathan M Davis <jmdavisProg@gmx.com> wrote:

> On Saturday, May 05, 2012 02:30:00 Manu wrote:
> > On 4 May 2012 23:16, Jakob Ovrum <jakobovrum@gmail.com> wrote:
> > > Perhaps it would be better if "a" was declared like this:
> > >> ref(int) a ();
> > >
> > > ref is not a type qualifier, I think that would be even more
> confusing. It
> > > would be completely out of sync with the rest of the language.
> >
> > But maybe it should be, then you'd be able to declare ref variables anywhere, like in C++... what's the disadvantage of that?
>
> I know that Walter's against it, but unfortunately, I don't recall his arguments. But I'd certainly be very surprised if it ever happened.
>

Yes, I get that impression also. But it seems strange, it would automatically solve these problems, and as a handy bonus, it would be useful in lots of other situations! :)


February 19, 2014
Hi,

are there any news about this problem ?

This code does compile.
[code]
ref int min(ref int lhs,ref int rhs) {
	return lhs > rhs ? rhs : lhs;
}
auto fptr = &min;

pragma(msg,typeof(fptr).stringof);  //int function(ref int lhs, ref int rhs) ref
[/code]

But how to manually specify type of fptr?

This does not compiles
[code]
int function(ref int lhs, ref int rhs) ref  fptr3 = &min; //Error:  no identifier for declarator int function(ref int lhs, ref int rhs)
[/code]

this one too.
[code]
ref int function(ref int lhs, ref int rhs)   fptr3 = &min; //Error: only parameters or foreach declarations can be ref
[/code]

Right now I am using dmd.2.065.0-rc1.
February 19, 2014
Hm [code] does not work.

Any way here is the test code.
http://melpon.org/wandbox/permlink/ZDz42rynoTaK1P4o


On Wednesday, 19 February 2014 at 16:20:39 UTC, Remo wrote:
> Hi,
>
> are there any news about this problem ?
>
> This code does compile.
> [code]
> ref int min(ref int lhs,ref int rhs) {
> 	return lhs > rhs ? rhs : lhs;
> }
> auto fptr = &min;
>
> pragma(msg,typeof(fptr).stringof);  //int function(ref int lhs, ref int rhs) ref
> [/code]
>
> But how to manually specify type of fptr?
>
> This does not compiles
> [code]
> int function(ref int lhs, ref int rhs) ref  fptr3 = &min; //Error:  no identifier for declarator int function(ref int lhs, ref int rhs)
> [/code]
>
> this one too.
> [code]
> ref int function(ref int lhs, ref int rhs)   fptr3 = &min; //Error: only parameters or foreach declarations can be ref
> [/code]
>
> Right now I am using dmd.2.065.0-rc1.

February 19, 2014
On Wednesday, 19 February 2014 at 16:20:39 UTC, Remo wrote:
> Hi,
>
> are there any news about this problem ?
>
> This code does compile.
> [code]
> ref int min(ref int lhs,ref int rhs) {
> 	return lhs > rhs ? rhs : lhs;
> }
> auto fptr = &min;
>
> pragma(msg,typeof(fptr).stringof);  //int function(ref int lhs, ref int rhs) ref
> [/code]
>
> But how to manually specify type of fptr?
>
> This does not compiles
> [code]
> int function(ref int lhs, ref int rhs) ref  fptr3 = &min; //Error:  no identifier for declarator int function(ref int lhs, ref int rhs)
> [/code]
>
> this one too.
> [code]
> ref int function(ref int lhs, ref int rhs)   fptr3 = &min; //Error: only parameters or foreach declarations can be ref
> [/code]
>
> Right now I am using dmd.2.065.0-rc1.

Looks like it's a bug. A workaround is:

typeof(&min) fprt = &min;

Or just use auto like in your example above.
February 19, 2014
> Looks like it's a bug.
How to report this bug ?

It is not possible to use auto because in real code the functions are extern(C).
> A workaround is: typeof(&min) fprt = &min;
Yes I already found this workaround, but it is really really ugly this way.

private ref int __hidden_fn_1002(ref int lhs,ref int rhs);
typeof(&__hidden_fn_1002) fprt;

Is there a way to make this much shorter?
Something like this ?
typeof(& (ref int __hidden_fn_1002(ref int lhs,ref int rhs))) fprt;



On Wednesday, 19 February 2014 at 16:47:08 UTC, Meta wrote:
> On Wednesday, 19 February 2014 at 16:20:39 UTC, Remo wrote:
>> Hi,
>>
>> are there any news about this problem ?
>>
>> This code does compile.
>> [code]
>> ref int min(ref int lhs,ref int rhs) {
>> 	return lhs > rhs ? rhs : lhs;
>> }
>> auto fptr = &min;
>>
>> pragma(msg,typeof(fptr).stringof);  //int function(ref int lhs, ref int rhs) ref
>> [/code]
>>
>> But how to manually specify type of fptr?
>>
>> This does not compiles
>> [code]
>> int function(ref int lhs, ref int rhs) ref  fptr3 = &min; //Error:  no identifier for declarator int function(ref int lhs, ref int rhs)
>> [/code]
>>
>> this one too.
>> [code]
>> ref int function(ref int lhs, ref int rhs)   fptr3 = &min; //Error: only parameters or foreach declarations can be ref
>> [/code]
>>
>> Right now I am using dmd.2.065.0-rc1.
>
> Looks like it's a bug. A workaround is:
>
> typeof(&min) fprt = &min;
>
> Or just use auto like in your example above.

February 19, 2014
On Wednesday, 19 February 2014 at 17:01:15 UTC, Remo wrote:
>
>> Looks like it's a bug.
> How to report this bug ?
>
> It is not possible to use auto because in real code the functions are extern(C).

Perhaps I'm missing something, but auto isn't incompatible with extern(C)
February 19, 2014
> Perhaps I'm missing something, but auto isn't incompatible with extern(C)

What I mean is that I only need to define function pointer to a function.
The function it self is extern and is a C++/C function.

February 19, 2014
On 02/19/14 17:20, Remo wrote:
> 
> This code does compile.
> [code]
> ref int min(ref int lhs,ref int rhs) {
>     return lhs > rhs ? rhs : lhs;
> }
> auto fptr = &min;
> 
> pragma(msg,typeof(fptr).stringof);  //int function(ref int lhs, ref int rhs) ref
> [/code]
> 
> But how to manually specify type of fptr?
> 
> This does not compiles
> [code]
> int function(ref int lhs, ref int rhs) ref  fptr3 = &min; //Error:  no identifier for declarator int function(ref int lhs, ref int rhs)
> [/code]
> 
> this one too.
> [code]
> ref int function(ref int lhs, ref int rhs)   fptr3 = &min; //Error: only parameters or foreach declarations can be ref
> [/code]

   alias extern(C) ref int function(ref int lhs, ref int rhs) Ftype;
   Ftype fprt;

artur
February 19, 2014
Excellent, this way is much better.

Thanks you artur.

On Wednesday, 19 February 2014 at 19:55:30 UTC, Artur Skawina wrote:
> On 02/19/14 17:20, Remo wrote:
>> 
>> This code does compile.
>> [code]
>> ref int min(ref int lhs,ref int rhs) {
>>     return lhs > rhs ? rhs : lhs;
>> }
>> auto fptr = &min;
>> 
>> pragma(msg,typeof(fptr).stringof);  //int function(ref int lhs, ref int rhs) ref
>> [/code]
>> 
>> But how to manually specify type of fptr?
>> 
>> This does not compiles
>> [code]
>> int function(ref int lhs, ref int rhs) ref  fptr3 = &min; //Error:  no identifier for declarator int function(ref int lhs, ref int rhs)
>> [/code]
>> 
>> this one too.
>> [code]
>> ref int function(ref int lhs, ref int rhs)   fptr3 = &min; //Error: only parameters or foreach declarations can be ref
>> [/code]
>
>    alias extern(C) ref int function(ref int lhs, ref int rhs) Ftype;
>    Ftype fprt;
>
> artur

February 19, 2014
"Remo" <remotion4d@googlemail.com> writes:

>> Looks like it's a bug.
> How to report this bug ?

https://d.puremagic.com/issues/
1 2 3
Next ›   Last »