[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libcdio-devel] Request for Comments: converting libcdio-paranoia C styl
From: |
Rocky Bernstein |
Subject: |
[Libcdio-devel] Request for Comments: converting libcdio-paranoia C style - which "standard" to use? |
Date: |
Mon, 13 May 2024 09:32:41 -0400 |
Recently, I put out a libcdio-paranoia release
https://github.com/rocky/libcdio-paranoia/releases/tag/release-10.2%2B2.0.2
to fix a bug that Whipper folks mentioned 6 years ago.
For those who have looked at the code, it largely follows the C style used
by the original cdparanoia code. This is a style that I have not
encountered in any other C code I have seen.
For example:
for(;endA<sizeA && endB<sizeB;endA++,endB++)
> if(buffA[endA]!=buffB[endB])break;
Back when this code was forked from cdparanoia, it was prudent to not try
to make gratuitous style changes; there was always the possibility that
cdparanoia would change and come out with a new release. However, there
haven't been changes to this code since 2008, 14 years ago when the
Subversion version control system was still popular.
I think it safe to say that there are not going to be any further releases
of or changes to the cdparanoia from which this was forked.
Code is not intended to be museum relics to be admired in a glass cage.
So I have been thinking about converting this code to some sort of current
C standard style. I came across clang-format
<https://clang.llvm.org/docs/ClangFormat.html> which is part of the LLVM
suite. It allows C to be reformatted according to various "preset" styles:
LLVM, GNU, Google, Chromium, Microsoft, Mozilla, Webkit, and a format you
specify which can be based on one of the presets (or not). Links to
information on the various styles can be found from
https://github.com/motine/cppstylelineup
The one small feature I like and use in code I see is not mentioned in any
of the existing guides. For #includes inside a #ifdef of some sort, I tend
to add spaces after the # to indicate the nesting level. For example:
#ifdef __GNU_LIBRARY__
# if defined __need_getopt && defined __USE_POSIX2 \
&& !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
/* The GNU getopt has more functionality ... *?
# ifdef __REDIRECT
extern int __REDIRECT_NTH (...)
# else
extern int __posix_getopt (int ___argc, char *const *___argv,
const char *__shortopts) __THROW;
# define getopt __posix_getopt
...
# endif
# endif
#else /* not __GNU_LIBRARY__ */
extern int getopt ();
#endif /* __GNU_LIBRARY__ */
But as in the past with things I tend to like but the others don't, I am
willing to adjust to the wishes of others. (As an old guy, I have been
beaten down by the Python standards fascists.)
I plan only doing this initially in libcdio-paranoia to see how it goes. If
a success we can contemplate for the libcdio (I have not forgotten about
doing yet another release...)
With all of this out of the way, now to the questions and request for
comments.
First, any thoughts or comments on this? Any thoughts on which of the many
C "standard" styles to use? (The great thing about Standards is that there
are so many to choose from!)
Is that #include indentation thing normal in a C standard style or just my
own one-off kind of thing. If not one-off, is there a way to indicate this
to clang-format?
Along with a C style, it would be also nice to add an .editorconfig
<https://editorconfig.org/> file.
- [Libcdio-devel] Request for Comments: converting libcdio-paranoia C style - which "standard" to use?,
Rocky Bernstein <=