Possible Duplicates:
Do I cast the result of malloc?
Should I explicitly cast malloc()'s return value?
Hello,
gcc 4.4.4 c89
Normally I don't cast the return result from a malloc call.
int *int_ptr = NULL;
int_ptr = malloc(sizeof(int));
However, I have read on here, that if you cast it can hide errors. How does it hide errors if you explicitly cast to an int?
int_ptr = (int*)malloc(sizeof(int));
Also, I was reading a c programming book that stated it was good programming practice to cast from a void pointer including a call from malloc.
Which would be good programming practice?
int *int_ptr = NULL;
void *ptr = NULL;
int_ptr = ptr;
or
int_ptr = (int*)ptr;
Many thanks for any advice,