Where is this behaviour documented (if it is at all)?
When you declare a pointer in C in the middle of a block, it will probably be in a wrong state (pointing to unusable memory) and you cannot use the standard if (a) free(a)
for freeing it.
The simplest program that comes to mind is
#include <stdlib.h>
int main(int argc, char *argv[]){
if(argc > 1) goto END;
char *a = NULL;
a = calloc(1,1);
END:
if(a) free(a);
}
Run the program without parameters and it works OK, if you run it with at least one parameter, it will probably break as follows: suprisingly (to me), if you compile it with clang, it may work (on my OS X it does, but on a NetBSD it does not). If you do with gcc, it always returns a
malloc: *** error for object 0x7fff5fc01052: pointer being freed was not allocated
Notice that the same program with the declaration at the head of the block is correct.
Edit: Notice that the question is about documentation. I realize doing what I describe is unsafe but I have found no place where it is explicitly shown.