Click to See Complete Forum and Search --> : parameter in function


shadowrider
01-23-2003, 08:34 PM
just wondering,
in C library for qsort it says : void qsort (void* base, size-t nel, size-t width, int (*compare) (const void *)(const void *));
so for the compare func, what does it mean by "const void"?
thx

The Kooman
01-23-2003, 11:45 PM
(const void *) means a pointer (*) that points to data of type "void" (void *) whose data is "const" (const void *), i.e whose data cannot be modified.

When a parameter to a function is declared to be const,

It tells the programmer that the function will not modify the contents of that argument
It ensures that the compiler will generate a warning when code in the function does try to modify the contents of the pointer


In either case, it basically tells you that the function will not play with contents of that parameter.

HTH

bigrigdriver
01-24-2003, 04:53 AM
It also means that (const void *) does not send anything to the function which it calls. The value is declared to be constant, therefore not changing. The * indicates that it is a pointer (points to the address where the data can be found). The void BETWEEN const and * indicates that it sends nothing to the called function. The 'void' preceding the function call indicates that nothing is sent back. Whatever happens, it happens in the function. Nothing goes in; nothing comes out.

shadowrider
01-26-2003, 01:39 PM
thx guys for the big help...
but one more thing, does anyone know how to implement merge sort in C using recursive? like, the function must have the same parameters as qsort.
i'm not sure...cause i don't think you can use the same parameters.
thx..