Many modern architectures use type with all bits set to zero, in which case:
void *p;
memset(&p, 0, sizeof(p));
assert(p == NULL); /* assertion holds on most architectures */
Just to be fully compliant I also explicitly set all pointers inside allocated struct to NULL. In case I directly call calloc (or any proxy function using calloc), compiler can figure out that calloc-allocated memory is already zeroed properly for x86's NULL and simply removes explicit NULL assignments, but in case I use a function pointer to calloc it obviously can't deduce it. How can I hint gcc (or MSVC) that these assignments can be removed safely?
Code example:
struct s *p = calloc(1, sizeof(*p));
p->ptr = NULL; /* optimized out */
calloc_ptr calloc_f = ...; /* points to calloc */
struct s *p = calloc_f(1, sizeof(*p));
p->ptr = NULL; /* isn't optimized out because compiler can't assume p's memory is already set to 0 */