Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jul 1995 09:08:47 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        bde@zeta.org.au, terry@cs.weber.edu
Cc:        bugs@freebsd.org
Subject:   Re: possible ffs_vget() race condition
Message-ID:  <199507202308.JAA10420@godzilla.zeta.org.au>

index | next in thread | raw e-mail

[Cc list trimmed]

>> The shift method has the advantage of giving the correct result :-).
>> You meant ((~(u_quad_t)0) >> 1).  This depends on u_quad_t being
>> larger than int.

>I don't understand why this would depend on quad being larger than int;
>because the naked 1 is of type int?

I should have said larger or the same size as an int.  ~(foo_t)0
is usually wrong if foo_t is shorter than an int (it is the same as
~0 because of the broken ANSI value-preserving promotion rules),
so using it gives a bad example for beginners to follow.  ((foo_t)(-1))
always works although you may need further casts (e.g., on the i386,
(u_short)(-1) is (int)0xffff, so shifting right 1 works right but
shifting left 16 and then shifting right gives surprising results.

The type of the shift count doesn't affect the type of the result.

Bruce


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199507202308.JAA10420>