[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH RFC] CODING_STYLE: document intended usage of types



On Mon, Feb 19, 2018 at 8:44 AM, Jan Beulich <JBeulich@xxxxxxxx> wrote:
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -88,6 +88,26 @@ Braces should be omitted for blocks with
>  if ( condition )
>      single_statement();
>
> +Types
> +-----
> +
> +Use basic C types and C standard mandated typedef-s where possible (and
> +with preference in this order).  This in particular means to avoid u8,
> +u16, etc
[snip]
> +Fixed width types should only be used when a fixed width quantity is
> +meant (which for example may be a value read from or to be written to a
> +register).

+1

> despite those types continuing to exist in our code base.

If CODING_STYLE doesn't already have a generic disclaimer like this,
we should make one.  I'm sure there are and will be lots of places
where the code doesn't match CODING_STYLE but should; we only need to
apologize for that once.

> +When signedness matters, qualify plain char, short, int, long, and
> +long long with "signed" or "unsigned".  Signedness is specifically
> +considered to matter when the valid value range of a variable covers
> +only non-negative values.  The prime example of such is a variable used
> +to index an array (negative array indexes, while they may occur, are
> +rather rare).

This paragraph is a bit confusing.  You say "when signedeness
matters", which I would interpret as saying, "When it matters whether
you use signed or unsigned values".  But is there ever a situation
where it doesn't matter whether we use signed or unsigned?  And the
second sentence says 'signedness' (which means 'being signed or
unsigned'), but then describe a situation where 'unsigned' is
appropriate.

FWIW I agree with Andy, that adding 'signed' should be avoided; 'long'
is signed already, 'signed long' is redundant.

Also, a brief motivation for why it's important to use unsigned when
we don't expect negative numbers would be helpful.  Otherwise it seems
a bit arbitrary.

I'd write this paragraph this way:

"Unsigned types should be used anywhere we can rule out negative
values.  Common examples include variables used to index an array,
loop counters, [other common examples]. [Why this helps.]"

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.