www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CDECL Utility

reply jpl <none nospam.com> writes:
Hi, 

Is there any utility in D like the CDECL for C? 

http://www.cs.vassar.edu/cgi-bin/man2html?cdecl+1

Regards
Dec 29 2007
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"jpl" <none nospam.com> wrote in message 
news:fl67kd$peu$1 digitalmars.com...
 Hi,

 Is there any utility in D like the CDECL for C?

 http://www.cs.vassar.edu/cgi-bin/man2html?cdecl+1

 Regards
With D's simple declaration syntax, is it necessary? Just read right-to-left. char* s; Pointer to char. void function(int sig, void function(int))(int) signal; Pointer to a function that takes (an int and a (pointer to a function that takes an int and returns void)) and returns void. void function(int) signal_function; Pointer to a function that takes an int and returns a function. int[][int delegate(char[])] aa; Associative arrays that maps from (delegates that take a char[] and return an int) to arrays of ints.
Dec 29 2007
next sibling parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 Hi,
 Is there any utility in D like the CDECL for C?

 http://www.cs.vassar.edu/cgi-bin/man2html?cdecl+1

 Regards
With D's simple declaration syntax, is it necessary? Just read right-to-left.
Seems like you need it...
 void function(int sig, void function(int))(int) signal;
^^^^^
 
 Pointer to a function that takes (an int and a (pointer to a function that 
 takes an int and returns void)) and returns void.
 
What's that "(int)" doing here? And would that even compile?
 void function(int) signal_function;
 
 Pointer to a function that takes an int and returns a function.
 
Isn't it rather a pointer to a function that takes an int and returns void? Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHdtJzd0kWM4JG3k8RAjaoAJ90SQ1ArQ2iWA25Jow3hBPr1mPGHwCfQR/s IcZwai/g5Txsd/QHFCzcIw0= =Eu7M -----END PGP SIGNATURE-----
Dec 29 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
""Jérôme M. Berger"" <jeberger free.fr> wrote in message 
news:fl6jpl$1git$1 digitalmars.com...

 void function(int sig, void function(int))(int) signal;
^^^^^
 Pointer to a function that takes (an int and a (pointer to a function 
 that
 takes an int and returns void)) and returns void.
What's that "(int)" doing here? And would that even compile?
I was trying to convert the C declaration into D from the cdecl page.. I have no idea what the (int) is doing in _that_ decl, but it at least is not valid D :o
 Pointer to a function that takes an int and returns a function.
Isn't it rather a pointer to a function that takes an int and returns void?
Typo :P
Dec 29 2007
parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 ""J�r�me M. Berger"" <jeberger free.fr> wrote in message 
 news:fl6jpl$1git$1 digitalmars.com...
 
 void function(int sig, void function(int))(int) signal;
^^^^^
 Pointer to a function that takes (an int and a (pointer to a function 
 that
 takes an int and returns void)) and returns void.
What's that "(int)" doing here? And would that even compile?
I was trying to convert the C declaration into D from the cdecl page.. I have no idea what the (int) is doing in _that_ decl, but it at least is not valid D :o
Apparently cdecl doesn't like it either :D : cdecl> explain void (*signal(int sig, void (*func)(int)))(int); syntax error However if you remove the parameter names in the declaration, you get: cdecl> explain void (*signal(int, void (*)(int)))(int); declare signal as function (int, pointer to function (int) returning void) returning pointer to function (int) returning void So I think that the proper D declaration would be: void function (int sig, void function (int)) function (int) signal; And like you said, the D way does not need something like cdecl to be interpreted (in fact, I find the D declaration clearer than the cdecl output). Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHd0NPd0kWM4JG3k8RAtP+AKCTgnz5nvDDFfzcua3Y5epXQLGwugCglRbL /W2JkTFplrLjgCsAV2p1C1Y= =QjCf -----END PGP SIGNATURE-----
Dec 29 2007
parent reply jpl <none nospam.com> writes:
Jérôme M. Berger Wrote:

 cdecl> explain void (*signal(int, void (*)(int)))(int);
 declare signal as function (int, pointer to function (int) returning
 void) returning pointer to function (int) returning void
 
 	So I think that the proper D declaration would be:
 void function (int sig, void function (int)) function (int) signal;
Then the pointers to functions in D are not read from right to left? In your example I understand: pointer to function(int) that returns a pointer to function(int sig, pointer to function(int) returning void) that returns void. I have no problems to understand any declaration in C but I don't get the D style...
Dec 30 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"jpl" <none nospam.com> wrote in message 
news:fl8ftn$25o8$1 digitalmars.com...

 So I think that the proper D declaration would be:
 void function (int sig, void function (int)) function (int) signal;
Then the pointers to functions in D are not read from right to left?
I think Jerome got it wrong too XD "declare signal as function (int, pointer to function (int) returning void) returning pointer to function (int) returning void" in D would be alias void function(int) signal(int, void function(void)); Notice I used an alias and put signal in the middle, since the C is declaring a *function* and not a *function pointer*.
Dec 30 2007
next sibling parent reply jpl <none nospam.com> writes:
Jarrett Billingsley Wrote:

 "jpl" <none nospam.com> wrote in message 
 news:fl8ftn$25o8$1 digitalmars.com...
 
 So I think that the proper D declaration would be:
 void function (int sig, void function (int)) function (int) signal;
Then the pointers to functions in D are not read from right to left?
I think Jerome got it wrong too XD "declare signal as function (int, pointer to function (int) returning void) returning pointer to function (int) returning void" in D would be alias void function(int) signal(int, void function(void));
alias void function(int) signal(int, void function(int));
 Notice I used an alias and put signal in the middle, since the C is 
 declaring a *function* and not a *function pointer*.
 
 
And how would it be the declaration without the alias in D? Thanks
Dec 30 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"jpl" <none nospam.com> wrote in message 
news:fl8sqm$2t8e$1 digitalmars.com...

 alias void function(int) signal(int, void function(void));
alias void function(int) signal(int, void function(int));
X(
 And how would it be the declaration without the alias in D?
void function(int) function(int, void function(int)) signal; Now it's a function pointer.
Dec 30 2007
parent jpl <none nospam.com> writes:
Jarrett Billingsley Wrote:

 "jpl" <none nospam.com> wrote in message 
 news:fl8sqm$2t8e$1 digitalmars.com...
 
 alias void function(int) signal(int, void function(void));
alias void function(int) signal(int, void function(int));
X(
 And how would it be the declaration without the alias in D?
void function(int) function(int, void function(int)) signal; Now it's a function pointer.
Ah... OK, now, without the alias I get it ; ) Thanks
Dec 30 2007
prev sibling parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 "jpl" <none nospam.com> wrote in message 
 news:fl8ftn$25o8$1 digitalmars.com...
 
 So I think that the proper D declaration would be:
 void function (int sig, void function (int)) function (int) signal;
Then the pointers to functions in D are not read from right to left?
I think Jerome got it wrong too XD "declare signal as function (int, pointer to function (int) returning void) returning pointer to function (int) returning void" in D would be alias void function(int) signal(int, void function(void)); Notice I used an alias and put signal in the middle, since the C is declaring a *function* and not a *function pointer*.
On second thought, I think you got it right, except that there shouldn't be an alias here: it should simply be: void function (int) signal (int, void (function (int)); The "alias" version would actually be equivalent to: typedef void (*signal(int, void (*)(int)))(int); Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHeCSmd0kWM4JG3k8RAlz5AKCrezQ0toLki+0SrxGgVkw1imjQYQCfZwO7 o6doMlNQrIpMORuMAMIwgMc= =LlDL -----END PGP SIGNATURE-----
Dec 30 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
""Jérôme M. Berger"" <jeberger free.fr> wrote in message 
news:fl98b7$pl1$1 digitalmars.com...

 void function (int) signal (int, void (function (int));
This is a function prototype, not a type decl :) The linker would then expect to find this function somewhere else.
 The "alias" version would actually be equivalent to:

 typedef void (*signal(int, void (*)(int)))(int);
:| I'm not entirely sure what that means. But the alias makes signal a function type: alias void function(int) signal(int, void function(int)); //signal s; // error, cannot declare s as function type signal* s; // OK, s is a function pointer
Dec 30 2007
parent =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 ""J�r�me M. Berger"" <jeberger free.fr> wrote in message 
 news:fl98b7$pl1$1 digitalmars.com...
 
 void function (int) signal (int, void (function (int));
This is a function prototype, not a type decl :) The linker would then expect to find this function somewhere else.
So is the C version when it doesn't have the "typedef". You would find this in a header file: - -------------------->8==================== void (*signal(int, void (*)(int)))(int); ====================8<-------------------- And this in the associated source file: - -------------------->8==================== void (*signal(int, void (*)(int)))(int) { // Code for the signal function } ====================8<--------------------
 The "alias" version would actually be equivalent to:

 typedef void (*signal(int, void (*)(int)))(int);
:| I'm not entirely sure what that means. But the alias makes signal a function type: alias void function(int) signal(int, void function(int)); //signal s; // error, cannot declare s as function type signal* s; // OK, s is a function pointer
And the equivalent in C: - -------------------->8==================== typedef void (*signal(int, void (*)(int)))(int); signal s1; // OK: s1 is a function, but it needs to be // defined somewhere signal* s2; // OK: s2 is a function pointer ... s2 = s1; // Now, s2 points to the s1 function ... void (*s1 (int val, void (*func)(int)))(int) { // Code for the s1 function } ====================8<-------------------- Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHeLwQd0kWM4JG3k8RAqokAKCVivJtyS+A0K7A6bMk3Y+zArNiygCfd1a6 /SwkE4tJwgNp3APdM9HlpoU= =RGqw -----END PGP SIGNATURE-----
Dec 31 2007
prev sibling parent jpl <none nospam.com> writes:
Jarrett Billingsley Wrote:

 
 void function(int) signal_function;
 
 Pointer to a function that takes an int and returns a function.
 
(void (*)(int))signal_function; This is really; cast signal_function to pointer to a function(int) that returns void.
Dec 30 2007
prev sibling parent BCS <ao pathlink.com> writes:
How about a tool that parses a type and displays a parse tree? How about 
the other way, edit the parse tree and it give you the type? I'm thinking 
a GUI app of some sort.
Dec 30 2007