As I've understood from the answers to this related question, an uninitialized pointer can contain pretty much anything and could therefore also happen to equal to NULL
. Is there a way to distinguish uninitialized pointers from null pointers, for example by giving them a specific value?
For example, consider:
// could potentially print
FILE *f1;
if (f1 == NULL)
fprintf(stderr, "f1 is NULL");
// will never print, but is this a good/safe way?
FILE *f2 = -1;
if (f2 == NULL)
fprintf(stderr, "f2 is NULL");