Re: Help requested with P99-based macro to create Wayland listeners

Liste des GroupesRevenir à cl c  
Sujet : Re: Help requested with P99-based macro to create Wayland listeners
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 10. Apr 2024, 18:40:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uv6fec$12hjm$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 10/04/2024 18:08, Tim Rentsch wrote:
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
 
David Brown <david.brown@hesbynett.no> writes:
>
On 09/04/2024 22:20, Blue-Maned_Hawk wrote:
>
David Brown wrote:
>
On 09/04/2024 20:17, Blue-Maned_Hawk wrote:
>
Tim Rentsch wrote:
>
What is it that you want to accomplish?
>
As i stated in the subject line, i am trying to create a macro to
create Wayland listeners.
>
Assume, for the sake of argument, that no one knows or cares anything
about Wayland or listeners.
>
<https://xkcd.com/1432/>
>
You are trying to use a set macros to expand to some code.  Start by
showing what code you want to get from examples of using your macros -
then people can try to help get the macros right.
>
MAKE_LISTENER(wl_registry, global, global_remove);
?
static const struct wl_registry_listener wl_registry_listener = { .global
= callback_wl_registry_global, .global_remove =
callback_wl_registry_global_remove };
>
#define _get_6th_arg(_1, _2, _3, _4, _5, _arg, ...) _arg
#define _fe_0(_global, _call, ...)
#define _fe_1(_global, _call, x) _call(_global, x)
#define _fe_2(_global, _call, x, ...) _call(_global, x) _fe_1(_global,
  _call, __VA_ARGS__)
#define _fe_3(_global, _call, x, ...) _call(_global, x) _fe_2(_global,
  _call, __VA_ARGS__)
#define _fe_4(_global, _call, x, ...) _call(_global, x) _fe_3(_global,
  _call, __VA_ARGS__)
#define expand_macro_for_each(_global, _macro, ...) \
     _get_6th_arg("ignored", __VA_ARGS__, \
     _fe_4, _fe_3, _fe_2, _fe_1, _fe_0)(_global, _macro, __VA_ARGS__)
>
>
#define MAKE_LISTENER(object_type, ...) _make_listener(object_type,
  __VA_ARGS__)
#define _listener_entry(_global, _field) , . _field = callback_ ## _global
## _ ## field
>
s/field/_field/
Correct - sorry about the typo.

 The bigger problem is that the proposed solution doesn't work
for more than five fields. 
I have no idea how many fields the OP might want, in order to judge if that is a big problem or not.  But I believe he'll be able to figure out how to extend it as necessary.

Clearly the idea is to define a
macro that works for an unlimited number of fields, or at least
a fairly large number.
If you have a way to extend it to unlimited numbers of fields, I would love to know - as far as I am aware, the lack of recursion or loops in the C pre-processor means that you always have to be limited like this. It is, I think, possible to make sequence of macros like this that split lists in half, so that you only need O(log N) submacros in order to support up to N arguments.  That would let you get to the level of very large numbers pretty quickly.

Date Sujet#  Auteur
9 Apr 24 * Help requested with P99-based macro to create Wayland listeners22Blue-Maned_Hawk
9 Apr 24 +* Re: Help requested with P99-based macro to create Wayland listeners16Tim Rentsch
9 Apr 24 i`* Re: Help requested with P99-based macro to create Wayland listeners15Blue-Maned_Hawk
9 Apr 24 i `* Re: Help requested with P99-based macro to create Wayland listeners14David Brown
9 Apr 24 i  `* Re: Help requested with P99-based macro to create Wayland listeners13Blue-Maned_Hawk
10 Apr 24 i   +* Re: Help requested with P99-based macro to create Wayland listeners11David Brown
10 Apr 24 i   i+* Re: Help requested with P99-based macro to create Wayland listeners3Ben Bacarisse
10 Apr 24 i   ii`* Re: Help requested with P99-based macro to create Wayland listeners2Tim Rentsch
10 Apr 24 i   ii `- Re: Help requested with P99-based macro to create Wayland listeners1David Brown
10 Apr 24 i   i`* Re: Help requested with P99-based macro to create Wayland listeners7David Brown
10 Apr 24 i   i `* Re: Help requested with P99-based macro to create Wayland listeners6Chris M. Thomasson
10 Apr 24 i   i  `* Re: Help requested with P99-based macro to create Wayland listeners5David Brown
10 Apr 24 i   i   +* Re: Help requested with P99-based macro to create Wayland listeners2bart
10 Apr 24 i   i   i`- Re: Help requested with P99-based macro to create Wayland listeners1Chris M. Thomasson
10 Apr 24 i   i   `* Re: Help requested with P99-based macro to create Wayland listeners2Chris M. Thomasson
10 Apr 24 i   i    `- Re: Help requested with P99-based macro to create Wayland listeners1Chris M. Thomasson
10 Apr 24 i   `- Re: Help requested with P99-based macro to create Wayland listeners1Tim Rentsch
10 Apr 24 +* Re: Help requested with P99-based macro to create Wayland listeners4James Kuyper
10 Apr 24 i+- Re: Help requested with P99-based macro to create Wayland listeners1Blue-Maned_Hawk
10 Apr 24 i+- Re: Help requested with P99-based macro to create Wayland listeners1Tim Rentsch
11 Apr 24 i`- Re: Help requested with P99-based macro to create Wayland listeners1Lawrence D'Oliveiro
11 Apr 24 `- Re: Help requested with P99-based macro to create Wayland listeners1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal