Wednesday 17 April 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...