digitalmars.D.learn - CDECL Utility
- jpl (4/4) Dec 29 2007 Hi,
- Jarrett Billingsley (14/18) Dec 29 2007 With D's simple declaration syntax, is it necessary? Just read
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (20/39) Dec 29 2007 -----BEGIN PGP SIGNED MESSAGE-----
- Jarrett Billingsley (6/18) Dec 29 2007 I was trying to convert the C declaration into D from the cdecl page.. I...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (27/42) Dec 29 2007 -----BEGIN PGP SIGNED MESSAGE-----
- jpl (4/10) Dec 30 2007 Then the pointers to functions in D are not read from right to left?
- Jarrett Billingsley (8/11) Dec 30 2007 I think Jerome got it wrong too XD
- jpl (5/23) Dec 30 2007
- Jarrett Billingsley (5/8) Dec 30 2007 X(
- jpl (3/19) Dec 30 2007 Ah... OK, now, without the alias I get it ; )
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (20/37) Dec 30 2007 -----BEGIN PGP SIGNED MESSAGE-----
- Jarrett Billingsley (9/12) Dec 30 2007 This is a function prototype, not a type decl :) The linker would then
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (40/60) Dec 31 2007 -----BEGIN PGP SIGNED MESSAGE-----
- jpl (3/8) Dec 30 2007 (void (*)(int))signal_function;
- BCS (3/3) Dec 30 2007 How about a tool that parses a type and displays a parse tree? How about...
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
"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 RegardsWith 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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jarrett Billingsley wrote:Seems like you need it...Hi,With D's simple declaration syntax, is it necessary? Just read right-to-left.Is there any utility in D like the CDECL for C? http://www.cs.vassar.edu/cgi-bin/man2html?cdecl+1 Regardsvoid 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
""Jérôme M. Berger"" <jeberger free.fr> wrote in message news:fl6jpl$1git$1 digitalmars.com...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 :ovoid 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?Typo :PPointer 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?
Dec 29 2007
-----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...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-----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 :ovoid 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?
Dec 29 2007
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
"jpl" <none nospam.com> wrote in message news:fl8ftn$25o8$1 digitalmars.com...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*.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?
Dec 30 2007
Jarrett Billingsley Wrote:"jpl" <none nospam.com> wrote in message news:fl8ftn$25o8$1 digitalmars.com...alias void function(int) signal(int, void function(int));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));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?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
"jpl" <none nospam.com> wrote in message news:fl8sqm$2t8e$1 digitalmars.com...X(alias void function(int) signal(int, void function(void));alias void function(int) signal(int, void function(int));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
Jarrett Billingsley Wrote:"jpl" <none nospam.com> wrote in message news:fl8sqm$2t8e$1 digitalmars.com...Ah... OK, now, without the alias I get it ; ) ThanksX(alias void function(int) signal(int, void function(void));alias void function(int) signal(int, void function(int));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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jarrett Billingsley wrote:"jpl" <none nospam.com> wrote in message news:fl8ftn$25o8$1 digitalmars.com...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-----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*.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?
Dec 30 2007
""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
-----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...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<--------------------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.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-----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 31 2007
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
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