Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #384279
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Help requested with P99-based macro to create Wayland listeners |
| Date | 2024-04-10 19:56 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <864jc81uaj.fsf@linuxsc.com> (permalink) |
| References | <pan$3770d$7f0531e6$76520fa1$2c09330e@invalid.invalid> |
Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
> This macro doesn't work and i don't know why. I've tried multiple
> different things to try to delay the expansion of _0MAKE_LISTENER
> and none of them have worked. I don't know if there's a more
> idiomatic way to do this. I've tried looking at the output from
> putting it through ?cpp? and that didn't work because it errored
> out before i could see what it expanded to.
>
> #define MAKE_LISTENER(object_type, ...) static const struct\
> object_type##_listener object_type##_listener = { P99_SEQ(\
> _0MAKE_LISTENER, P99_SEQ((object_type), __VA_ARGS__)) }
> #define _0MAKE_LISTENER(x) _1MAKE_LISTENER (x, _2MAKE_LISTENER
> #define _1MAKE_LISTENER _3MAKE_LISTENER
> #define _2MAKE_LISTENER(y) y)
> #define _3MAKE_LISTENER _4MAKE_LISTENER
> #define _4MAKE_LISTENER(object_type, event_name) .event_name =\
> callback_##object_type##_##event_name
After a lot of trial and error, I came up with the code below.
Probably it could be simplified, but I was happy just to get
it to work.
#include "p99.h"
#define static_const_LISTENER( kind, ... ) \
static const PLAIN_LISTENER( kind, __VA_ARGS__ )
#define PLAIN_LISTENER( kind, ... ) \
struct LISTENER_TAG_NAME( kind ) LISTENER_TAG_NAME( kind ) = { \
LISTENER_FIELDS( kind, __VA_ARGS__ ) \
}
#define LISTENER_TAG_NAME( kind ) JOIN2( kind, _listener )
#define LISTENER_FIELDS( kind, ... ) \
P99_SEQ( AS_IS, \
P99_SEQ( ONE_LISTENER_FIELD_2 AS_IS, \
P99_SEQ( ONE_LISTENER_FIELD, P99_SEQ( (kind), __VA_ARGS__ ) ) \
) \
)
#define ONE_LISTENER_FIELD( a ) ONE_LISTENER_FIELDx( a )
#define ONE_LISTENER_FIELDx( a ) SINGLES_INTO_PAIR( a )
#define SINGLES_INTO_PAIR( a_b ) ( ONE_COMMA_TWO a_b )
#define ONE_COMMA_TWO( a ) a, AS_IS
#define AS_IS( a ) a
#define ONE_LISTENER_FIELD_2( a, b ) ONE_LISTENER_FIELD_2x( a, b )
#define ONE_LISTENER_FIELD_2x( kind, field ) \
.field = callback_ ## kind ## _ ## field
#define JOIN2( a, b ) JOIN2x( a, b )
#define JOIN2x( a, b ) a ## b
static_const_LISTENER( wl_registry, global, global_remove );
static_const_LISTENER(
xdg_wm_base,
configure, close, configure_bounds, wm_capabilities
);
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar
Help requested with P99-based macro to create Wayland listeners Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-04-09 00:36 +0000
Re: Help requested with P99-based macro to create Wayland listeners Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-04-09 09:22 -0700
Re: Help requested with P99-based macro to create Wayland listeners Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-04-09 18:17 +0000
Re: Help requested with P99-based macro to create Wayland listeners David Brown <david.brown@hesbynett.no> - 2024-04-09 21:59 +0200
Re: Help requested with P99-based macro to create Wayland listeners Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-04-09 20:20 +0000
Re: Help requested with P99-based macro to create Wayland listeners David Brown <david.brown@hesbynett.no> - 2024-04-10 11:05 +0200
Re: Help requested with P99-based macro to create Wayland listeners scott@slp53.sl.home (Scott Lurndal) - 2024-04-10 14:26 +0000
Re: Help requested with P99-based macro to create Wayland listeners David Brown <david.brown@hesbynett.no> - 2024-04-10 16:54 +0200
Re: Help requested with P99-based macro to create Wayland listeners "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-04-10 11:44 -0700
Re: Help requested with P99-based macro to create Wayland listeners David Brown <david.brown@hesbynett.no> - 2024-04-10 21:29 +0200
Re: Help requested with P99-based macro to create Wayland listeners bart <bc@freeuk.com> - 2024-04-10 20:39 +0100
Re: Help requested with P99-based macro to create Wayland listeners "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-04-10 13:55 -0700
Re: Help requested with P99-based macro to create Wayland listeners "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-04-10 13:40 -0700
Re: Help requested with P99-based macro to create Wayland listeners "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-04-10 13:48 -0700
Re: Help requested with P99-based macro to create Wayland listeners Ben Bacarisse <ben.usenet@bsb.me.uk> - 2024-04-10 15:49 +0100
Re: Help requested with P99-based macro to create Wayland listeners Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-04-10 09:08 -0700
Re: Help requested with P99-based macro to create Wayland listeners David Brown <david.brown@hesbynett.no> - 2024-04-10 18:40 +0200
Re: Help requested with P99-based macro to create Wayland listeners Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-04-10 09:03 -0700
Re: Help requested with P99-based macro to create Wayland listeners James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-04-10 02:49 -0400
Re: Help requested with P99-based macro to create Wayland listeners Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-04-10 13:57 +0000
Re: Help requested with P99-based macro to create Wayland listeners Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-04-10 09:05 -0700
Re: Help requested with P99-based macro to create Wayland listeners Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-04-11 00:57 +0000
Re: Help requested with P99-based macro to create Wayland listeners Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-04-10 19:56 -0700
csiph-web