Thursday, September 12, 2019

When do I need to cast the result of malloc in C language?

Based on this old question malloc returns a pointer to void that it




is automatically and safely promoted to any other pointer type




But reading K&R I've found this following code



char *strdup(char *s)
{
char *p;
/* make a duplicate of s */
p = (char *) malloc(strlen(s)+1)


What is the difference?

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...