On December 17, 2011 17:30, in comp.lang.c,
wrote:
> **BUMP**
>
> Anyone is in this room ???
You should be aware that usenet is a /very/ asynchronous process; it takes
appreciable time for posts to propogate from server to server (sometimes
days), and /even more/ time for people to pull posts down from their server
and read them. Often, the response will involve a lot of detail, which
takes time to collect and transcribe.
In other words, be patient, little one.
>
> On Sat, 17 Dec 2011 22:20:16 +0000, paolo wrote:
>> Hi Everyone,
>>
>> It is known that function free() of c library expects parameter of
>> type void* and when we invoke them with pointers to any type, compiler
>> automatically performs the typecast, can anyone let me know as to why
>> pointers are typecasted to void* in many places before performing
>> operation on them?
The C standard requires void pointers (that is, pointer to void) in a number
of places where the logic requires that such pointer refer to one of a
number of different types, depending on other indicators. (the argument
pointers passed to printf() and scanf() come to mind here). When prototyped
functions accept void pointers, the compiler converts from typed pointer to
void pointer as part of the function call sequence. Similarly, when
prototyped functions return a void pointer, the compiler converts to typed
pointer as part of the function return sequence.
AFAIK, there is no requirement in the standard that the programmer
explicitly cast typed pointers to void pointers. I may be wrong here, and I
expect those with better knowledge of the standard to correct me.
However, other languages (read C++) /do/ have requirements for explicit
casts of typed pointers to void pointers. Programmers used to working with
those languages often mistakenly cast pointers to void* in their C code.
Perhaps, this is the behaviour that you have noticed.
HTH
--
Lew Pitcher