> Thanks Ben. The cast makes sense. I think of void as being an invention
> to allow functions that return nothing, so the function return type
> (void *) tells me that a pointer is returned that points to a
> nonexistent variable. Is the (void *) just a reminder to always cast the
> return pointer to the variable type we happen to need?
>
Nope, in this case it's just a generic memory allocation function.
It can't know in advance how you'll call it, and it makes no sense to have a 
malloc() call for each data type possible.
It is actually impossible to do so.
To allow allocating memory for any type of struct, the malloc() call has 
been implemented so that it allocs space without caring what data goes 
there.
It simply returns a pointer to the starting memory location it reserved. And 
the most basic pointer is a void *, which doesn't point to a specific type 
of data stored, but simply to a storage address.
That's also the reason why you have to pass it the amount of space it needs 
to reserve (size_of(foo)).

Regards,
Alex


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to