www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C-style function pointer syntax supported?

reply Sean Kelly <sean f4.ca> writes:
I just noticed this last night:

alias void (*t1)();
alias void function() t2;

void fn() {}

void main()
{
     t1 f = &fn;
     t2 g = &fn;
}

This compiles just fine.  Is the C syntax supported to ease porting or 
is it an artifact of a bygone day?  Should the syntax be deprecated?


Sean
Jan 18 2006
next sibling parent John Reimer <terminal.node gmail.com> writes:
Sean Kelly wrote:
 I just noticed this last night:
 
 alias void (*t1)();
 alias void function() t2;
 
 void fn() {}
 
 void main()
 {
     t1 f = &fn;
     t2 g = &fn;
 }
 
 This compiles just fine.  Is the C syntax supported to ease porting or 
 is it an artifact of a bygone day?  Should the syntax be deprecated?
 
 
 Sean
I know the C syntax has been supported for awhile in D. It certainly makes header conversion much easier. Yet, I prefer the clarity of the D style; when I port C code to D, I almost always convert the function pointers to the D style as well. -JJR
Jan 18 2006
prev sibling next sibling parent "Ameer Armaly" <ameer_armaly hotmail.com> writes:
"Sean Kelly" <sean f4.ca> wrote in message 
news:dqltqq$125l$1 digitaldaemon.com...
I just noticed this last night:

 alias void (*t1)();
 alias void function() t2;

 void fn() {}

 void main()
 {
     t1 f = &fn;
     t2 g = &fn;
 }

 This compiles just fine.  Is the C syntax supported to ease porting or is 
 it an artifact of a bygone day?  Should the syntax be deprecated?
I would support depricating it, since the D syntax is much more explicit and clear.
 Sean 
Jan 18 2006
prev sibling parent Don Clugston <dac nospam.com.au> writes:
Sean Kelly wrote:
 I just noticed this last night:
 
 alias void (*t1)();
 alias void function() t2;
 
 void fn() {}
 
 void main()
 {
     t1 f = &fn;
     t2 g = &fn;
 }
 
 This compiles just fine.  Is the C syntax supported to ease porting or 
 is it an artifact of a bygone day?  Should the syntax be deprecated?
 
 
 Sean
At the very least, the D syntax should be the one used in error messages. It's a bit silly that an error message involving t2 will describe it as void (*t2)()
Jan 18 2006