Please note this question is not about malloc
in C or malloc
vs new
/smart pointers in C++.
If I use malloc
in C++, what kind of cast should I use? The following all work.
int *a = (int *)malloc(sizeof (int));
int *b = static_cast<int *>(malloc(sizeof (int)));
int *c = reinterpret_cast<int *>(malloc(sizeof (int)));
Live example: http://ideone.com/lzfxcm
I prefer to use C++ style casts in my code as much as possible and I want to adopt safe coding habits. Please advise with this in mind.
Thank you.