prototype (?) of function passed to function 
Author Message
 prototype (?) of function passed to function

What's wrong with this (ANSI C)?  DEC C gives the following warning:

    (void) qsort(str,njmer,sizeof(STRING),(int (*)(const char *str_1, const char *str_2))strcmp);
..........................................^
%CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer
value "(int ...)strcmp" is "function (pointer to const char, pointer to
const char) returning int", which is not compatible with
"function (pointer to const void, pointer to const void) returning int".

Is it a problem because str_1 and str_2 are not defined elsewhere???

The compiler doesn't like the parameter list empty either:

    (void) qsort(str,njmer,sizeof(STRING),(int (*)()) strcmp);
...............................................^
%CC-W-NOPARMLIST, The declaration of an abstract function type has an empty
parameter list.  If the function has parameters, they should be declared
here; if it has no parameters, "void" should be specified
in the parameter list.

Thanks,

David Mathog

Manager, sequence analysis facility, biology division, Caltech



Sat, 16 Mar 2002 03:00:00 GMT  
 prototype (?) of function passed to function
last argument to qsort from <stdlib.h>  should be of type  int  (*)(const void*,const void *)
so you need to, in your function call,
make  typecast   (int (*)(const void*,const void *))
and
   qsort(str,njmer,sizeof(STRING),(int (*)(const void *,const void *)) strcmp)

grzegorz

Quote:

> What's wrong with this (ANSI C)?  DEC C gives the following warning:

>     (void) qsort(str,njmer,sizeof(STRING),(int (*)(const char *str_1, const char *str_2))strcmp);
> ..........................................^
> %CC-W-PTRMISMATCH, In this statement, the referenced type of the pointer
> value "(int ...)strcmp" is "function (pointer to const char, pointer to
> const char) returning int", which is not compatible with
> "function (pointer to const void, pointer to const void) returning int".

> Is it a problem because str_1 and str_2 are not defined elsewhere???

> The compiler doesn't like the parameter list empty either:

>     (void) qsort(str,njmer,sizeof(STRING),(int (*)()) strcmp);
> ...............................................^
> %CC-W-NOPARMLIST, The declaration of an abstract function type has an empty
> parameter list.  If the function has parameters, they should be declared
> here; if it has no parameters, "void" should be specified
> in the parameter list.

> Thanks,

> David Mathog

> Manager, sequence analysis facility, biology division, Caltech



Tue, 19 Mar 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP- PASSING STRUCTURE IN FUNCTION PROTOTYPE?

2. Function returning a function-pointer - how to prototype ?

3. Function prototypes for pointers to functions.

4. HELP: function prototype with pointer to function as parameter

5. Passing "callback" function to a function

6. passing a function to function.

7. Passing functions to functions?

8. Pointer to function passed to varargs function

9. HELP:Passing functions to functions(!)

10. Novice: Passing a function pointer to a function

11. Passing a function to a function the hard way

12. Prototyping a function passed a pointer to a function

 

 
Powered by phpBB® Forum Software