Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!news.miami.edu!umiami!bxpfac From: bxpfac@umiami.ir.miami.edu Newsgroups: comp.lang.c Subject: Is this bsearch call portable? Message-ID: <1991Apr10.094540.8841@umiami.ir.miami.edu> Date: 10 Apr 91 13:45:40 GMT Reply-To: devebw9f@miavax.ir.miami.edu Organization: Univ of Miami IR Lines: 37 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