Type Safety
malloc returns a void pointer (void *), which indicates that it is a pointer to a region of unknown data type. The use of casting is only required in C++ due to the strong type system, whereas this is not the case in C. The lack of a specific pointer type returned from malloc is type-unsafe behaviour according to some programmers: malloc allocates based on byte count but not on type. This is different from the C++ new operator that returns a pointer whose type relies on the operand. (see C Type Safety).
One may "cast" (see type conversion) this pointer to a specific type:
There are advantages and disadvantages to performing such a cast.
Read more about this topic: C Dynamic Memory Allocation
Famous quotes containing the words type and/or safety:
“This type of man who is devoted to the study of wisdom is always most unlucky in everything, and particularly when it comes to procreating children; I imagine this is because Nature wants to ensure that the evils of wisdom shall not spread further throughout mankind.”
—Desiderius Erasmus (c. 14661536)
“He had a gentleman-like frankness in his behaviour, and as a great point of honour as a minister can have, especially a minister at the head of the treasury, where numberless sturdy and insatiable beggars of condition apply, who cannot all be gratified, nor all with safety be refused.”
—Philip Dormer Stanhope, 4th Earl Chesterfield (16941773)