简体   繁体   English

如果两个文件指针指向同一个文件,关闭其中一个是否足够?

[英]If two file pointers point to the same file, is closing one of them enough?

If I have two file pointers and do the following: 如果我有两个文件指针,请执行以下操作:

FILE *f1,*f2;
f1= fopen("inputfile","r+");
f2=f1;
fclose(f2);

Is the equal operation valid, if it is, will the last line close f1 as well? 相等运算是否有效(如果有效),最后一行也将关闭f1吗?

It is enough, both will be closed and both will point to a closed file. 足够了,两个都将关闭并且都将指向一个关闭的文件。

Assigning f2=f1 doesn't do anything magical (increasing a reference count or duplicating descriptors). 分配f2=f1并没有什么神奇的事情(增加引用计数或复制描述符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C:将两个文件指针同步到同一个文件 - C: Synchronising two file pointers to the same file 两个相同名称的静态变量(两个不同的文件)和其他任何文件中的外部变量 - Two static variables in same name(two different file) and extern one of them in any other file 连接两个文件指针 - Concatenate two file pointers 确定两个文件路径是否指向Linux / C下的同一文件? - Determining if two file paths point to same file under Linux / C? 如何检查两个文件名是否指向同一个物理文件 - How to check whether two file names point to the same physical file 当2个指针指向同一区域并且其中1个被释放时会发生什么? - What happens when 2 pointers point to same area and 1 of them is freed? 为什么两个相同值的整数指针指向同一个东西(via ==)? - Why are two integer pointers of the same value point to the same thing (via ==) ? 有两个指针指向相同内存块的正确方法 - Proper way to have two pointers point to the same memory chunk 为什么这两个应该相同的指针指向不同的数据? - Why do these two pointers that should be the same point to different data? 如何从一个文件中读取两个矩阵并添加它们? [等候接听] - How to read two matrices from one file and add them? [on hold]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM