Just a quick question I couldn't find a question on:
double* array = (double*) malloc(ARRAY_SIZE * sizeof(double));
or can I simply
double* array = malloc(ARRAY_SIZE * sizeof(double));
is there any difference?
Just a quick question I couldn't find a question on:
double* array = (double*) malloc(ARRAY_SIZE * sizeof(double));
or can I simply
double* array = malloc(ARRAY_SIZE * sizeof(double));
is there any difference?
In C, you shouldn't cast since it can hide certain subtle errors. In C++ (since your question originally had that tag despite no mention in the body), you have to cast.
The "subtle errors" of which I speak include strange behaviour when your integers and pointers are different sizes and you haven't included the header for malloc
- in that case, you may find it assuming it returns an int
(losing information in the process) and, while the compiler would normally warn about that, the explicit cast will probably prevent that.