Is this bsearch call portable?
bxpfac at umiami.ir.miami.edu
bxpfac at umiami.ir.miami.edu
Wed Apr 10 23:45:40 AEST 1991
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 at miavax.ir.miami.edu
More information about the Comp.lang.c
mailing list