The*_*ere 2 c c++ fopen file fclose
以下代码是否会导致未定义的行为?
FILE *fp;
fopen_s(&fp, "abc.bin", "rb");
fclose(fp);
fclose(fp); // accidentally closed an already closed file.
Run Code Online (Sandbox Code Playgroud)
我知道在已经释放的数组上调用free会导致UB.因此我问.
引用自man fclose
:
如果stream参数是非法指针,或者已经传递给先前调用fclose()的描述符,则fclose()的行为是未定义的.
所以是的,它是未定义的行为.