원문: http://drdobbs.com/cpp/231902043?pgno=2|The Different Meanings of void]
- K&R C에서는 void가 없었기 때문에 malloc()의 return type은 char *였음
- Standard C에서는 void *가 도입되어 malloc()와 free()에서 사용됨
void * malloc(size_t size);
void free(void *ptr);
- void *는 T *로, T *는 void *로 변환 가능함
- 문제점
- 아래 예제처럼 double *가 long *로 변경될 수 있는 부작용이 존재함
double *pd;
long *pl;
void *pv;
...
pv = pd; // compiles in C
...
pl = pv; // compiles in C
- C++에서는 void *를 T *로 변환하는 것을 캐스팅하지 않고서는 안 되도록 변경하였음
pv = pd; // compiles in C and C++
...
pl = pv; // compiles in C, but not in C++
pl = (long *)pv; // compiles in C and C++