Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type

Steven Rostedt <[email protected]> Sat, 7 Feb 2026 09:16:12 -0500
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <20260207091612.2bb72f61@robin>
On Sat, 7 Feb 2026 13:04:02 +0800
Donglin Peng <[email protected]> wrote:

> > > +#define for_each_enum(i, enum_type, member)                  \
> > > +     for (i = 0, member = btf_enum(enum_type);               \
> > > +          i < BTF_INFO_VLEN(enum_type->info);                \
> > > +          i++, member++)  
> >
> >
> > You can make the above into:
> >
> >  #define for_each_enum(enum_type, member)                       \
> >         for (int __i = 0, member = btf_enum(enum_type);         \
> >              __i < BTF_INFO_VLEN((enum_type)->info);            \
> >              __i++, member++)
> >
> > Then you don't need to pass in the counter "i".  
> 
> Sorry, I found that the previous change causes a build failure.
> 
> The error occurs in trace-btf.c:36:
> warning: initialization of 'int' from 'struct btf_enum *' makes
> integer from pointer without a cast [-Wint-conversion]
>    36 |         for (int __i = 0, member = btf_enum(enum_type); \
> 
> This is due to the member variable being redefined as an int type,
> conflicting with its assignment of a struct btf_enum *pointer from
> btf_enum(enum_type).

Ah, I had that issue before. But this should work:

 #define for_each_enum(enum_type, member)				\
	member = btf_enum(enum_type);					\
	for (int __i = 0; __i < BTF_INFO_VLEN((enum_type)->info);	\
	     __i++, member++)

Just can't use it as a single line for if statements.

	if (x)
		for_each_enum() {
		}

But we shouldn't be doing that anyway.

-- Steve