lkml.org 
[lkml]   [2022]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop
From
Date
On Thu, 2022-03-03 at 11:31 +0800, Xiaomeng Tong wrote:
> On Wed, 02 Mar 2022 08:02:23 -0500, James Bottomley
> <James.Bottomley@HansenPartnership.com> wrote:
> > pos shouldn't be an input to the macro since it's being declared
> > inside
> > it. All that will do will set up confusion about the shadowing of
> > pos.
> > The macro should still work as
> >
> > #define list_for_each_entry_inside(type, head, member) \
> > ...
> >
> > For safety, you could
> >
> > #define POS __UNIQUE_ID(pos)
> >
> > and use POS as the loop variable .. you'll have to go through an
> > intermediate macro to get it to be stable. There are examples in
> > linux/rcupdate.h
>
> The outer "pos" variable is no longer needed and thus the declare
> statement before the loop is removed, see the demostration in PATCH
> 3~6. Now, there is only one inner "pos" variable left. Thus, there
> should be no such *shadow* problem.

So why is pos in the signature of your #define then? Because that
means it expands to whatever goes in the first field of
list_for_each_entry_inside().

If someone needs to specify a unique name to avoid shadowing an
existing variable, then hide pos and use UNIQUE_ID instead was the
whole thrust of this comment.

James


\
 
 \ /
  Last update: 2022-03-06 15:34    [W:0.049 / U:0.728 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site