gpt4 book ai didi

c - ftello/fseeko 与 fgetpos/fsetpos

转载 作者:太空狗 更新时间:2023-10-29 16:44:51 30 4
gpt4 key购买 nike

ftello/fseekofgetpos/fsetpos 有什么区别?两者似乎都是文件指针获取/设置函数,它们使用不透明的偏移类型有时允许 64 位偏移。

它们是否受不同平台或不同标准的支持?它使用的偏移类型是否更灵活?

而且,顺便说一下,我知道 what is difference between fgetpos/fsetpos and ftell/fseek ,但这不是重复项。该问题询问有关 ftell/fseek 的问题,答案适用于 ftello/fseeko。

最佳答案

参见 Portable Positioning有关差异的详细信息。摘录:

On some systems where text streams truly differ from binary streams, it is impossible to represent the file position of a text stream as a count of characters from the beginning of the file. For example, the file position on some systems must encode both a record offset within the file, and a character offset within the record.

As a consequence, if you want your programs to be portable to these systems, you must observe certain rules:

  • The value returned from ftell on a text stream has no predictable relationship to the number of characters you have read so far. The only thing you can rely on is that you can use it subsequently as the offset argument to fseek or fseeko to move back to the same file position.
  • In a call to fseek or fseeko on a text stream, either the offset must be zero, or whence must be SEEK_SET and the offset must be the result of an earlier call to ftell on the same stream.
  • The value of the file position indicator of a text stream is undefined while there are characters that have been pushed back with ungetc that haven't been read or discarded. See Unreading.

简而言之:fgetpos/fsetpos 使用更灵活的结构来存储有关文件位置状态的额外元数据,从而实现更大的可移植性(理论上)。

关于c - ftello/fseeko 与 fgetpos/fsetpos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12119132/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com