bxpfac@umiami.ir.miami.edu (04/10/91)
Is the following call to bsearch portable? Note that 's' is the key to be searched and is a pointer to 'char' whereas 'fun' is an array of 'FUN'. Also note that the function 'funcmp' uses only the string 'fun_name' for comparison. (I have not used casts in call to bsearch since I am using prototypes). ---------------------- char s[] = "fun2"; pfun = (FUN *) bsearch (&s, fun, nfun, sizeof (FUN), funcmp); ---------------------- DECLARATIONS of variables used above. typedef struct { char *fun_name; double (*fun_ptr) (double); } FUN; FUN fun[] = {{"fun1", fun1}, {"fun2", fun2}, }; int nfun = sizeof (fun) / sizeof (FUN); FUN *pfun; /*===========================================================================*/ int funcmp (void *p1, void *p2) { return (strcmp (((FUN *) p1)->fun_name, ((FUN *) p2)->fun_name)); } Thanks. Bimal / devebw9f@miavax.ir.miami.edu