anonymous functions

Peter da Silva peter at ficc.UUCP
Fri May 20 00:23:11 AEST 1988


In article <862 at xyzzy.UUCP>, throopw at xyzzy.UUCP writes:
>         signal( SIGINT, void (int sig){ interrupted = 1; } );

>         qsort( (void *)tbl, n_elt, n_elt*sizeof(tbl_elt_t),
>                int (void *a, void *b){
>                    return( strcmp( (tbl_elt_t *)a->name, 
>                                    (tbl_elt_t *)b->name ) ); } );

> 	/* crummy hash function, but good enough for whatever purpose: */
>         hfind( name, table, int (char *s){ return(*s); } );

I think that the syntax is a bit wedged here. What you're actually doing
is akin to typecasting:

	(void (*)(int sig)){ interrupted = 1; }
	(int (*)(void *a, void *b)) { ... }
	(int (*)(char *s)){ return s; }

A bit more verbose, but should require less patching of the language
definition.
-- 
-- Peter da Silva, Ferranti International Controls Corporation.
-- Phone: 713-274-5180. Remote UUCP: uunet!nuchat!sugar!peter.



More information about the Comp.lang.c mailing list