sysdeps/unix/sysv/linux/lseek.c on ILP32 question
Steve Ellcey
sellcey@caviumnetworks.com
Tue Feb 21 19:53:00 GMT 2017
On Tue, 2017-02-21 at 20:37 +0100, Andreas Schwab wrote:
> On Feb 21 2017, Steve Ellcey <sellcey@caviumnetworks.com> wrote:
>
> >
> > int main()
> > {
> > char fname[1024], buf[1024];
> > int x, fd, val;
> On x32, off_t is a 64-bit type.
>
> Andreas.
OK, I see if I change:
 val = lseek(fd, -(sizeof(crmsg) - 1), 1);
to
 val = lseek(fd, -((off_t) sizeof(crmsg) - 1), 1);
I get the result I want.
But I am not entirely sure why, I guess it is a question of exactly how
integer conversions are done. Â I have a prototype for lseek so it
should be converted to off_t before the call but why do I need to
convert the result of sizeof before negating? Â Is it because sizeof
returns an unsigned type and negating the unsigned type results in a
zero instead of a negative value?
Steve Ellcey
sellcey@cavium.com
More information about the Libc-alpha
mailing list