[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] gpsd style change?
From: |
Eric S. Raymond |
Subject: |
Re: [gpsd-dev] gpsd style change? |
Date: |
Wed, 11 Feb 2015 14:13:17 -0500 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Greg Troxel <address@hidden>:
> > I don't understand how C89 vs. C99 enters into it. Explain?
>
> My memory is a bit fuzzy. Long ago, one could only declare variables at
> the top of a function, before any statements. I think that's still true
> in C89, and C99 permitted arbitrary ordering (as a nod to C++).
There are actually three possible restrictions:
1. Declarations allowed only at the beginning of a function block.
2. Declarations allowed at the beginning of any block.
3. Declarations may intermix with executable code.
I believe that C89 allowed 2 and that if any compiler had restriction 1 it
was very far back, like in pcc days. But my memory is also fuzzy, I could
be wrong about this. Gary might be able to say something definite.
> > For the record, I do assume C99. Among other things, the code makes
> > significant use of bool, designated initializers, and inline.
>
> That seems entirely reasonable in 2015.
> There does seem to be a trailing-edge attitude in the embedded world
> about sticking to C89 much longer than others did.
That certainly used to be true. On the other hand, I have yet to hear
about *any* embedded porting issue re GPSD that reduces to "C99
feature, aaarggh!" so those days may be behind us. Since, oh, 2006 or
so, I think. Embedded toolchains are a hell of a lot less quirky than
they were a decade ago.
> > However, I don't intermix declarations with executable statements because
> > that gives splint the screaming fantods (dies with an internal error). Nor
> > does the code use variadic macros, flexible arrays, type-generic math,
> > or type complex.
>
> Entirely reasonable, but should be documented.
New draft section for the Hacking Guide:
<h2 id="standards">C, standards and style</h2>
<p>The C code is written with a large subset of C99. You are
encouraged to use <code>bool</code>, designated initializers,
<code>inline</code> and <code>restrict</code>. Do not assume
that type specifiers will default to int.</p>
<p>You are allowed, but not required, to use C99 // comments.</p>
<p>Though C99 allows it, do not intermix declarations with executable
statements within a block, because that gives one of our code checkers
the screaming fantods (splint dies with an internal error). Do,
however, declare variables at the front of the <em>smallest</em> enclosing
block.</p>
<p>The code does <em>not</em> use C99 variadic macros, flexible
arrays, type-generic math, or type complex. Think carefully before
introducing these and don't do it without discussion on the
development list first.</p>
<p>Avoid dependencies on GCC and glibc, as we must support embedded
environments using (for example) uClibc.</p>
<p>We are pretty laissez-faire about indent style and low-level C
formatting. Be aware that if your patch seems disharmonious with what
is around it, your code may be reformatted, so try to blend in.</p>
<p>You may rely on a full POSIX and Single Unix Standard binding to
the operating system.</p>
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
signature.asc
Description: Digital signature