Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

All function declarations/defintions and variable declaration/defintions one one line

30 views
Skip to first unread message

Frederick Gotham

unread,
Sep 2, 2019, 6:30:40 AM9/2/19
to

For the past 17 years, I've become accustomed to reading function declarations like this:

int MyFunc(double x);

I'm working on a project now though where there's function declarations like this:

int
MyFunc
(double x);

I've tried a few different code beautifiers and none of them can turn this into a one-liner.

Anyone got a tool for this?

Barry Schwarz

unread,
Sep 2, 2019, 2:25:30 PM9/2/19
to
If you tell us which tools you have already tried, you might receive
more useful responses.

--
Remove del for email

Bonita Montero

unread,
Sep 2, 2019, 2:32:50 PM9/2/19
to
> I'm working on a project now though where there's function declarations like this:
>
> int
> MyFunc
> (double x);

I would acceppt any common style, but this is idiotic.

Vir Campestris

unread,
Sep 2, 2019, 4:39:29 PM9/2/19
to
You're right, it's horrible.

But don't change it.

If you do everyone from now on looking at the file's history in the
source control system to find out what idiot wrote that stupid function
declaration will find the author is one fgotham...

Andy

Keith Thompson

unread,
Sep 2, 2019, 6:06:51 PM9/2/19
to
Are most or all function declarations in the project like that? Is it
part of the style guide for the project? If so, consider leaving it
alone.

I've seen styles that require function names to be at the beginning of
the line.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Louis Krupp

unread,
Sep 3, 2019, 12:04:34 AM9/3/19
to
On Mon, 2 Sep 2019 03:30:31 -0700 (PDT), Frederick Gotham
<cauldwel...@gmail.com> wrote:

>
Pipe the source files one at a time through:

===
#!/bin/bash

perl -0777 -pe 's/(\w)\s*\n\s*(\()/$1$2/g'
===

It turns this:

===
int
MyFunc1
(double x);

int
MyFunc1a
(double x);

int
MyFunc2 (double x);

void s1(void)
{
int a = 7 +
(8);
}

void s2(void)
{
int a = MyFunc1
(8);
}

===

into this:

===
int
MyFunc1(double x);

int
MyFunc1a(double x);

int
MyFunc2 (double x);

void s1(void)
{
int a = 7 +
(8);
}

void s2(void)
{
int a = MyFunc1
(8);
}
===

Try it. It might make things better. Or it might make them much, much
worse.

Louis

Juha Nieminen

unread,
Sep 3, 2019, 10:16:46 AM9/3/19
to
What should happen if the names of the function and its parameters, and the types, are together
so long that they would make the line overly long (like several hundreds characters long)?
0 new messages