Qsort call with pointer to c ++ function

I found a book that says that if you want to use a function from the standard C library that takes a function pointer as an argument (e.g. qsort), the function to which you want to pass the function pointer must be a C function and therefore declared Like extern "C".

eg.

extern "C" {
  int foo(void const* a, void const* b) {...}
}

... 
qsort(some_array, some_num, some_size, &foo);

I would not be surprised if this is simply incorrect information, however - I am not so sure: is this correct?

+3
source share
2 answers

, , , , ++. . .

: ++, C. , extern "C".

, , . , , , , , , .

OTOH, : ++, qsort ? ++ std::sort - .

+5

.

extern C , ++ C-; C- . ( C).

+5

Source: https://habr.com/ru/post/1787813/


All Articles