Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2012 12:37:50 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Pawel Jakub Dawidek <pjd@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Bruce Evans <brde@optusnet.com.au>
Subject:   Re: svn commit: r236917 - head/sys/kern
Message-ID:  <20120613115111.R5323@besplex.bde.org>
In-Reply-To: <20120612115117.GB1372@garage.freebsd.pl>
References:  <201206112017.q5BKHKsW007722@svn.freebsd.org> <20120612114254.V1572@besplex.bde.org> <20120612115117.GB1372@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 12 Jun 2012, Pawel Jakub Dawidek wrote:

> On Tue, Jun 12, 2012 at 12:53:47PM +1000, Bruce Evans wrote:
>> On Mon, 11 Jun 2012, Pawel Jakub Dawidek wrote:
>>> -        KASSERT(fd >= 0 && fd < fdp->fd_nfiles,
>>> +        KASSERT((unsigned int)fd < fdp->fd_nfiles,
>>>             ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles));
>>> 	return ((fdp->fd_map[NDSLOT(fd)] & NDBIT(fd)) != 0);
>>> }
>>
>> This is backwards.  Apart from using the worst possible (most verbose)
>> spelling of `unsigned', it uses a type hack manually optimize away the
>> test for fd being < 0.  The compiler will do this "optimization"
>> automatically if it is any good (or undo it if it is not), so all the
>> hack does is obfuscate the test.  With the verbose spelling of u_int,
>> it even takes more space.
>
> Well, to be honest I presonally would prefer explicit check for fd being
> less than 0, but my impression was that using cast is the most popular
> way and I wanted this check to be consistent across our source tree.
>
> Feel free to change it.

I'm only free to ask you to back out it out.

> BTW. I really dislike using 'unsigned' with omitted 'int'. u_int is fine.

I really dislike 'unsigned int'.  The int in it is just noise, as in
'long int'.

>From K&R 1: p34: "The declarations for the qualifiers look like [...]
unsigned int x;  The word int can be omitted in such situations, and
typically is."  p45: example that uses plain unsigned.  p183: "Unisgned
integers, declared unsigned, ...".  p193: [semi-formal grammar]:
"type-specifier: char, short, int, long, unsigned, float, double,
struct-or-union-specifier, typedef-name.  [short int, long int,
unsigned int, long float are also acceptable]".

>From K&R 2: p36: same as above p34.  p49: similar to above p45 (now
missing in index; no longer "implicit int" for the function return
type; excessive use of unsigned fixed).  p196: similar to above p183
(now says "...declared using the unsigned keyword).  p211: similzr to
above p193 (add void, signed, enum-specifier; remove long float, and
tighten up the description of which combinations are allowed in other
ways).

Other interesting points from K&R:
- according to the grammar, both `unsigned' and 'signed' are full-fledged
   types, not qualifiers for integer types.  You can even write plain
   'signed' meaning 'signed int', but no one does that.
- K&R very rarely uses `unsigned'.  This shows that it should rarely be
   used.  I could only find the above examples in it (these are all that
   are in the index for K&R 1), plus 1 more a page later than the p45/49
   one (the index is broken in a different way for this -- in K&R 1 the
   one on p46 is not indexed, while in K&R 2 the one on p49 is not
   indexed).

Bruce



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