c - What is char * const *? -
so seems means a pointer constant pointer char
. points char * const
, far good.
what gets me confused , how saw used. looking @ man page qsort
, example following convert pointers elements of char **
(an array of strings), (pointers elements seen const void *
) normal char pointers feedable strcmp
:
static int cmpstringp(const void *p1, const void *p2) { /* actual arguments function "pointers pointers char", strcmp(3) arguments "pointers char", hence following cast plus dereference */ return strcmp(* (char * const *) p1, * (char * const *) p2); }
my question is, why there cast char * const *
? why isn't const char **
(because want send const char *
strcmp
)?
char * const *
indeed means pointer constant pointer chars. reason cast performed in code in question following:
p1
, p2
(non-const) pointers constant location. let's assume type of location const t
.
now want cast p1
, p2
real types. know each element of array char *
, therefore t = char *
. const t
constant pointer char, written char * const
.
since p1
, p2
pointers elements of array, of type const t *
, char * const *
.
since function merely calls strcmp
, in truth wouldn't have made difference if parameters cast char **
or const char **
or const char * const *
or whatever.
Comments
Post a Comment