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
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
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/
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(constpthread_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/