Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Jan 2005 10:26:30 +0000
From:      Paul Richards <paul@originative.co.uk>
To:        arch@freebsd.org
Subject:   Re: c99/c++ localised variable definition
Message-ID:  <20050131102630.GJ61409@myrddin.originative.co.uk>
In-Reply-To: <20050128173327.GI61409@myrddin.originative.co.uk>
References:  <20050128173327.GI61409@myrddin.originative.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 28, 2005 at 05:33:27PM +0000, Paul Richards wrote:
> People used to programming in C++ or Perl (and many others) are used
> to defining variables as near to use as possible. This have never been
> possible before in C, but now with c99 it is.

Ok, to sum up  the discussion then:

1) In the kernel the issue of stack usage is a relevant consideration
against adopting the new style.
2) Sprinkling definitation all over the place may not be a postitive
step forward, but in practice this is already occuring with local
scope creationg.
3) Usage in for loops may be more useful than other uses.
4) The new style has benefits for const usage and initialisation.

There was one strong dissenting comment from DES with regard to
sloppy programming technique but I think sloppy programming is an
issue anyway and the best way to counter it is to enforce adherence
to style(9).The issue under consideration is whether we can improve
some aspects of style given the new syntax available.

I agree with the issue that sprinkling definitions arbitrarily all
over the code does not aid readibility or reliability of the code.
I think the loop usage though is one clear example where it is
clearer. I think there are others as well; where the usage of the
variable is clearly localised it is much easier to see a local
definition than to have to jump back and forth to find out what
variables are.

I'd suggest that we allow the use of c99 variable definitions in a
limited area of userland on a trial basis in order to gain some
experience of whether we do or do not gain anything from their
usage.  The conservatives might feel that FreeBSD is not the place
for such research but I disagree, I think that's exactly the sort
of thing FreeBSD should be doing.

> I noticed when trying to use this feature that we're not running
> the compiler with c99 fully supported yet so I guess that's perhaps
> the first step to discuss.

This wasn't really discussed, I think at the very least we should
enable c99 as the base system compiler so that 1) we can be sure our
code works with c99 and 2) it's available as the default compiler for
third party use.

At the risk of really throwing the cat amongst the pigeons, I
compiled cat with c++ over the weekend just to see if the
better(different) checking turned anything up and I found a couple
of loose casting situations. It got me wondering whether a c++
compilation option wouldn't be a beneficial way of linting the code.

-- 
Paul Richards



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