Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!decwrl!decvax!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP (Wayne A. Throop) Newsgroups: comp.lang.c Subject: anonymous functions Message-ID: <862@xyzzy.UUCP> Date: 10 May 88 21:55:53 GMT References: <5773@sigi.Colorado.EDU> <11325@mimsy.UUCP> <282@teletron.UUCP> <11385@mimsy.UUCP> Organization: Data General, RTP NC. Lines: 33 > chris@mimsy.UUCP (Chris Torek) Once again, Chris writes the exact article I had in mind, only better than I might have done it. I have only one nit to pick. In telling "what good are they" of anonymous functions, Chris says: > As for uses, anonymous functions are much like anonymous aggregates: > you use them to pass to other functions, or to set local variables > (in C, pointers to functions). ... which is exactly correct, but he omits giving a convincing example, like to supply a signal handler routine that just sets an external bit, or a compare or swap routine for a qsort, or a hash routine for a table manipulation routine, or whatever. The point is, why name this little bit of code that is required to be a function because of the way the library is organized? When extremely short as in these examples, giving it a name is silly and wastefull. Example invocations: 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); } ); -- He wonders if he too might have made a similar mistake. --- "Seen and Not Seen" by Talking Heads from "Remain in Light" -- Wayne Throop!mcnc!rti!xyzzy!throopw