On Fri, Mar 10, 2017 at 03:27:38PM +0000, Bernd Edlinger wrote: > I have a question regarding the following code: > > > char *p; > [...] > free(p); > if (p != NULL) { > printf("the pointer was non-zero\n"); > } else { > printf("the pointer was null\n"); > } > > > I would not have expected any problem with code like this, > which uses the pointer value after the free function was called, > as long as it does not dereference the pointer. > > > But in the N1570 annex J.2, the following is written: > > "The behavior is undefined in the following circumstances: > ... > The value of a pointer that refers to space deallocated by a call to the > free or realloc function is used (7.22.3)." > > So does this mean, that the above C code uses undefined behavior? Annex J is informative only, and the things in there are quite shortened, it's just a summary; I don't see anything in 7.22.3 itself that would make this undefined behaviour. Segher