This may be a deeper question than I expect, but can you see if a character pointer is unallocated? For example, a string that is unallocated is not NULL, as seen from when I ran this code:
char *ptr; /* Unallocated char pointer */
if (ptr == NULL) {
ptr = malloc(10); /* Not casted cause it doesn't matter */
printf("ptr is allocated\n");
return(0);
}
printf("ptr is unallocated\n");
return(0);
When I ran the code, I received the message ptr is unallocated. That makes sense because the string could not have memory for a null character. So, is there any way to see if a string is unallocated? Or am I asking the wrong question?