Jump to page: 1 2
Thread overview
CDECL Utility
Dec 29, 2007
jpl
Dec 29, 2007
Jérôme M. Berger
Dec 30, 2007
Jérôme M. Berger
Dec 30, 2007
jpl
Dec 30, 2007
jpl
Dec 30, 2007
jpl
Dec 30, 2007
Jérôme M. Berger
Dec 31, 2007
Jérôme M. Berger
Dec 30, 2007
jpl
Dec 31, 2007
BCS
December 29, 2007
Hi,

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

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

Regards

December 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
>
> 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.


December 29, 2007
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   |
+---------------------------------+------------------------------+
December 30, 2007
""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


December 30, 2007
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   |
+---------------------------------+------------------------------+
December 30, 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...


December 30, 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.
December 30, 2007
"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*.


December 30, 2007
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

December 30, 2007
"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.


« First   ‹ Prev
1 2