将fpos_t转换为int或char [英] Cast fpos_t to int or char
问题描述
我正在使用一个函数,该函数对文件的长度使用按位操作: fpos_t flen;
I'm working with a function that uses bitwise operations with the length of a file: fpos_t flen;
当我尝试将其转换为int或char,或尝试对其进行算术运算时,会失败并出现以下编译错误:
错误:在期望整数时使用的聚合值
When I try casting it to an int or char, or attempt on arithmetic operation on it, it fails with the following compilation error:
error: aggregate value used where an integer was expected
推荐答案
您误用了该类型。首先,它不代表长度。它代表一个位置。其次,它只是用于调用 fsetpos
。你不是要对它进行算术,因为它不一定代表一个数字类型。它包含您的库需要能够执行 fsetpos
操作的任何信息。在你的库的实现中, fpos_t
似乎是一个聚合类型,例如一个struct。 (您可以检查头文件中的定义,但不要依赖于您在其中发现的任何内容;在其他平台或您的标准库的未来版本中它们会有所不同。)
You're misusing that type. First, it doesn't represent a length. It represents a position. Second, it's only meant to use in a call to fsetpos
. You're not meant to do arithmetic on it because it doesn't necessarily represent a numeric type. It contains whatever information your library needs to be able to perform an fsetpos
operation. In your library's implementation, fpos_t
appears to be an aggregate type, such as a struct. (You can check the definition in the header files to be sure, but don't rely on whatever you discover there; it's liable to differ on other platforms or in future versions of your standard library.)
对于你的下一步,考虑问一个更直接的问题,如何解决你正在处理的任何问题,当你想出了在 fpos_t
。
As for your next step, consider asking a more direct question about how to solve whatever problem you were working on when you came up with the idea to do bitwise operations on a fpos_t
.
这篇关于将fpos_t转换为int或char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!