On 26.07.2017 02:56, Andrei Alexandrescu wrote:
What Moritz is saying is that the following implementation of fclose
is correct according to the C standard:
int fclose(FILE *stream){
if(stream == NULL){
return go_wild_and_corrupt_all_the_memory();
}else{
return actually_close_the_file(stream);
}
}
I'd think that would be the case, but failed to find a fgetc
implementation that mentions it's undefined for a null FILE*. Is there a
link? Thx. -- Andrei
It's implicit. In C, whenever you pass something that is outside the
interface specification, you get UB. Also, in C, there is no way to get
a segmentation fault except for UB, and fgetc(NULL) segfaults with glibc.