lkml.org 
[lkml]   [2024]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] Documentation: coding-style: ask function-like macros to evaluate parameters
Hi Stephen,
Thanks for reviewing.

On Wed, Mar 20, 2024 at 2:42 PM Stephen Rothwell <sfr@canb.auug.orgau> wrote:
>
> Hi Barry,
>
> On Wed, 20 Mar 2024 13:16:56 +1300 Barry Song <21cnbao@gmail.com> wrote:
> >
> > diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> > index 9c7cf7347394..8065747fddff 100644
> > --- a/Documentation/process/coding-style.rst
> > +++ b/Documentation/process/coding-style.rst
> > @@ -827,6 +827,13 @@ Macros with multiple statements should be enclosed in a do - while block:
> > do_this(b, c); \
> > } while (0)
> >
> > +Function-like macros should evaluate their parameters, for unused parameters,
> > +cast them to void:
> > +
> > +.. code-block:: c
> > +
> > + #define macrofun(a) do { (void) (a); } while (0)
> > +
>
> Maybe add some comment about using a static inline function for these
> simple versions instead, if at all possible, (it is suggested just
> above this section) since that will still type check arguments.

right, what about adding the below section together with the above (void) cast?

+Another approach could involve utilizing a static inline function to replace
+the macro.:
+
+.. code-block:: c
+
+ static inline void fun(struct foo *foo)
+ {
+ }
+

>
> --
> Cheers,
> Stephen Rothwell

Thanks
Barry

\
 
 \ /
  Last update: 2024-05-27 15:55    [W:0.763 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site