Clarifications about pointers use

This seams to be bad quality code! Maybe not dangerous, as const appears in prototype.

myFunc(const void * p) accepts a pointer to anything and const should mean it won’t touch it.

Now, st is a pointer to myStruct, so st->arr is the value of arr member and &st->arr is memory address of arr member. Assuming arr is an array, st->arr value is already a pointer.

So, (char**) is possibly the correct type of &st->arr, it is a pointer to a character array. And if it is the correct type, there is no need to cast!

You cast when you need to tell the compiler to handle your data as another data. It would make sense, in this case myFunc((const void *)&st->arr);

Anyway, without further information on myFunc, I belive that true programmer intention was myFunc((const void *) st->arr);

Leave a Comment