Skip to contentSkip to conversation

Formatting very long function parameters

DISCUSSION Alejandro Colomar (man-pages) 3 participants 3 messages Mar 8, 2021 – Mar 14, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Hi Michael,

I have a problem with pthread_mutexattr_getpshared(3).
After adding 'restrict', the first parameter alone would use 81 columns, so I came with 3 options:

A) Move the parameter to a new line,
leaving the open parenthesis at the end of a line.

[

       int pthread_mutexattr_getpshared(
                                     const pthread_mutexattr_t 
*restrict attr,
                                     int *restrict pshared);
       int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                                     int pshared);

]

B) Compact the pointer to use only 80 columns,
by deleting a cosmetic whitespace,
and exceptionally ignore the 78-column right margin.

[
int pthread_mutexattr_getpshared(const
pthread_mutexattr_t*restrict attr,

                                        int *restrict pshared);
       int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                                        int pshared);

]

C) (What POSIX does) Break the 1st parameter at the pointer:

[
int pthread_mutexattr_getpshared(const pthread_mutexattr_t
*restrict attr, int *restrict pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
]

I did the 1st one, but I'm not sure about it. Do you have any preference?

This is only problematic when both the function name and the 1st parameter are very long, which is rare, so it shouldn't appear in many pages. I don't expect to find another case. Option B) might not be an option if there are more like this (if those use >82 columns).

Thanks,

Alex

Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#1 lore raw

hi,
since no one answered i will give my personal view:
I would go for A)
if that does not fit try to compress names (if possible) and ignore the 78 Char boundary.

NTL:
having names that long is questionable in the first place (not your fault, i know).

re,
wh
________________________________________
Von: Alejandro Colomar (man-pages) <[email protected]>
Gesendet: Montag, 8. März 2021 14:54:01
An: Michael Kerrisk (man-pages)
Cc: linux-man
Betreff: Formatting very long function parameters

Hi Michael,

I have a problem with pthread_mutexattr_getpshared(3).
After adding 'restrict', the first parameter alone would use 81 columns, so I came with 3 options:

A) Move the parameter to a new line,
leaving the open parenthesis at the end of a line.

[

        int pthread_mutexattr_getpshared(
                                      const pthread_mutexattr_t
*restrict attr,
                                      int *restrict pshared);
        int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                                      int pshared);

]

B) Compact the pointer to use only 80 columns,
by deleting a cosmetic whitespace,
and exceptionally ignore the 78-column right margin.

[
int pthread_mutexattr_getpshared(const
pthread_mutexattr_t*restrict attr,

                                         int *restrict pshared);
        int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                                         int pshared);

]

C) (What POSIX does) Break the 1st parameter at the pointer:

[
int pthread_mutexattr_getpshared(const pthread_mutexattr_t
*restrict attr, int *restrict pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
]

I did the 1st one, but I'm not sure about it. Do you have any preference?

This is only problematic when both the function name and the 1st parameter are very long, which is rare, so it shouldn't appear in many pages. I don't expect to find another case. Option B) might not be an option if there are more like this (if those use >82 columns).

Thanks,

Alex

--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

#2 lore raw
In reply to Alejandro Colomar (man-pages)
Quoted 41 lines · Alejandro Colomar (man-pages)

Hi Michael,

I have a problem with pthread_mutexattr_getpshared(3).
After adding 'restrict', the first parameter alone would use 81 columns, so I came with 3 options:

A) Move the parameter to a new line,
leaving the open parenthesis at the end of a line.

[

        int pthread_mutexattr_getpshared(
                                      const pthread_mutexattr_t 
*restrict attr,
                                      int *restrict pshared);
        int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                                      int pshared);

]

B) Compact the pointer to use only 80 columns,
by deleting a cosmetic whitespace,
and exceptionally ignore the 78-column right margin.

[
int pthread_mutexattr_getpshared(const
pthread_mutexattr_t*restrict attr,

                                         int *restrict pshared);
        int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
                                         int pshared);

]

C) (What POSIX does) Break the 1st parameter at the pointer:

[
int pthread_mutexattr_getpshared(const pthread_mutexattr_t
*restrict attr, int *restrict pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
]

Quoted 1 line

I did the 1st one, but I'm not sure about it. Do you have any preference?

I think (A) is more or less the way to go. But, so long as we can't line anything up below the "(" of any function declaration, I decided to tweak that a little so that the follow-on arguments are not so deeply indented (which looks a little strange, I find). Thus my commit 48ee34e75.

Cheers,

Michael

Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/