Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast fpos_t to int or char

I'm working with a function that uses bitwise operations with the length of a file: fpos_t flen;

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

like image 651
sj755 Avatar asked Jan 17 '23 23:01

sj755


2 Answers

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.)

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.

like image 65
Rob Kennedy Avatar answered Jan 22 '23 13:01

Rob Kennedy


I was getting the same error when i was trying to do this: char aux = (char)flen & 15, where flen was fpos_t. I found a solution here: http://dsmarkchen.blogspot.com.br/2008/08/fpost.html . It should be: char aux = flen.__pos & 15.

like image 31
fmilani Avatar answered Jan 22 '23 12:01

fmilani