tech-userlevel archive

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

Re: style: clean up mentions of old-style C



On Sat, Apr 15, 2023 at 11:47:08AM +0200, Roland Illig wrote:
 > Since C90, function prototypes are available. They have become so common
 > now that mentioning them is more confusing than helpful. I suggest
 > removing these two lines:
 > 
 > >  * Use ANSI function declarations.  ANSI function braces look like
 > >  * old-style (K&R) function braces.
 > 
 > I don't know what 'ANSI function braces' are or how they might differ
 > from 'old-style function braces'. What is the point of this sentence,
 > and why is it needed?

How about (given what people have said about the sentence):

  * Use full function prototypes in all declarations and definitions.
  * The open-brace for a function body goes on its own line.

The second point is an important part of the traditional layout, and I
think the first is still worth stating. You _still_ see K&R-style
code, 35-odd years notwithstanding.

 > I also suggest this change:
 > > - * ANSI function declarations for private functions (i.e. functions not used
 > > - * elsewhere) and the main() function go at the top of the source module.
 > > + * Declarations for private functions (i.e. functions not used elsewhere) go
 > > + * at the top of the source module.
 > 
 > The words 'ANSI function' are redundant.

Also replace this notion of "private" with "file-static"; non-static
private functions shouldn't exist, and I'm reasonably certain
everything we expect to be style-compliant at all has had static
applied as needed.

Thus,

   * Declarations for file-static functions go at the top of the file.

Might say "Forward declarations" or even "Any needed forward
declarations".

I think we don't have an official stance on whether files should be
ordered caller-first or callee-first, and the code base includes
examples of both, but in the latter case forward declarations are rare
and unnecessary ones shouldn't be encouraged. (They serve no purpose
and create a maintenance headache.)

However, this point might warrant further discussion.

 > Declaring a prototype for 'main' is so uncommon that I don't see a point
 > mentioning it.

If it's going to be mentioned it should say "don't do that". It was a
thing at one point, but a stupid thing...

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index