I need to have a static void* array[1024]; in a library and i need to have it set to NULL for every entries.
My question is about the best way to set the entire array to NULL, is a memset (array, NULL, sizeof (void*) * 1024) the best solution?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
staticpointers are automatically initialized toNULL. See C99:TC3 6.7.8, §10:Also, contrary to what others have written,
isn’t guaranteed to result in null pointers. On some systems, a pointer with all its bits set to
0might actually be valid. For mainstream systems, that’s not the case, but with embedded systems, one never knows.The safe way to set all entries to a null pointer is to either loop over the entries yourself and set them to
NULL, or to use an uninitializedstaticarray which you canmemcpy()over the array you want to set toNULL.