December 30, 2007 Re: CDECL Utility | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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
|
December 30, 2007 Re: CDECL Utility | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley Attachments: | 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 | +---------------------------------+------------------------------+ |
December 31, 2007 Re: CDECL Utility | ||||
---|---|---|---|---|
| ||||
Posted in reply to jpl | 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. |
December 31, 2007 Re: CDECL Utility | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jérôme M. Berger | ""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 |
December 31, 2007 Re: CDECL Utility | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley Attachments: | 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 | +---------------------------------+------------------------------+ |
Copyright © 1999-2021 by the D Language Foundation