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
What is it that you want to accomplish?
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.
On 09/04/2024 20:17, Blue-Maned_Hawk wrote:
Tim Rentsch wrote:Assume, for the sake of argument, that no one knows or cares anything
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.
about Wayland or listeners.
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.
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(\
David Brown wrote:
On 09/04/2024 20:17, Blue-Maned_Hawk wrote:
Tim Rentsch wrote:Assume, for the sake of argument, that no one knows or cares anything
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.
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 };
This isn't a C problem, or at least,not entirely a C problem. I'd
thought that the P99 in your subject line might be a typo for C99, but I
have no idea what P99_SEQ is. Wikipedia knows 9 different meanings for
P99. Google gives me way too many hits from P99, I have no idea which
one is relevant. You might need to take this up with someone who has
some idea what P99 is.
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:Assume, for the sake of argument, that no one knows or cares anything
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.
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
#define _make_listener(object_type, first_field, ...) static const struct \
object_type ## _listener object_type ## _listener = { \
.first_field = callback_ ## object_type ## _ ## first_field \
expand_macro_for_each(object_type, _listener_entry, __VA_ARGS__) \
}
On 09/04/2024 22:20, Blue-Maned_Hawk wrote:
David Brown wrote:
On 09/04/2024 20:17, Blue-Maned_Hawk wrote:<https://xkcd.com/1432/>
Tim Rentsch wrote:Assume, for the sake of argument, that no one knows or cares anything
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.
about Wayland or listeners.
You are trying to use a set macros to expand to some code. Start byMAKE_LISTENER(wl_registry, global, global_remove);
showing what code you want to get from examples of using your macros -
then people can try to help get the macros right.
→
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
#define _make_listener(object_type, first_field, ...) static const struct \--
object_type ## _listener object_type ## _listener = { \
.first_field = callback_ ## object_type ## _ ## first_field \
expand_macro_for_each(object_type, _listener_entry, __VA_ARGS__) \
}
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:Assume, for the sake of argument, that no one knows or cares anything
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.
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
#define _make_listener(object_type, first_field, ...) static const struct \ >> object_type ## _listener object_type ## _listener = { \
.first_field = callback_ ## object_type ## _ ## first_field \
expand_macro_for_each(object_type, _listener_entry, __VA_ARGS__) \
}
Frankly I'd reject that code in any code review request.
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
};
?
MAKE_LISTENER(xdg_wm_base, configure, close, configure_bounds, wm_capabilities);
?
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
.configure = callback_xdg_wm_base_configure,
.close = callback_xdg_wm_base_close,
.configure_bounds = callback_xdg_wm_base_configure_bounds,
.wm_capabilities = callback_xdg_wm_base_wm_capabilities
};
On 4/8/24 20:36, Blue-Maned_Hawk wrote:
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(\
This isn't a C problem, or at least,not entirely a C problem. I'd
thought that the P99 in your subject line might be a typo for C99, but I
have no idea what P99_SEQ is. Wikipedia knows 9 different meanings for
P99. [...]
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/
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/
The bigger problem is that the proposed solution doesn't work
for more than five fields.
Clearly the idea is to define a
macro that works for an unlimited number of fields, or at least
a fairly large number.
On 10/04/2024 16:26, Scott Lurndal wrote:
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:Assume, for the sake of argument, that no one knows or cares anything >>>>> about Wayland or listeners.
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.
<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
#define _make_listener(object_type, first_field, ...) static const
struct \
object_type ## _listener object_type ## _listener = { \
.first_field = callback_ ## object_type ## _ ## first_field \
expand_macro_for_each(object_type, _listener_entry, __VA_ARGS__) \ >>> }
Frankly I'd reject that code in any code review request.
I normally like code to be so clear that comments about how it works are unnecessary. But I think for something like this, a few comments would
be helpful!
When doing this kind of messing around with advanced preprocessing, it's useful to have a set of re-usable macros that can be written and
documented once. The "expand_macro_for_each" macro and its parts is
partly there, and once that is in place and accepted, the rest is a lot smaller step to accept in a code review.
But this is code to help the OP get his macro generations working.
Whether he likes it, rejects it, or uses it for inspiration is up to him.
The OP needs a deep read of the chaos lib:
https://github.com/rofl0r/chaos-pp
Might help... ? ;^)
On 10/04/2024 20:44, Chris M. Thomasson wrote:
The OP needs a deep read of the chaos lib:
https://github.com/rofl0r/chaos-pp
Might help... ? ;^)
I think more people would respond to your posts if you actually included content, rather than just random links and smilies.
Assume that no one here will ever click on a youtube link - then you
clearly don't need to post them.
Assume that no one will click on any random webpage link, or even to
known sites like github, unless there's plenty of information in the
posts to make it clear why the linked software is relevant.
You do a lot of interesting programming, have interesting ideas, and are energetic about sharing them and helping people. That's all great. But you could do so much better at getting your thoughts across.
So if you don't mind - please try again. Tell us what "the chaos lib" is. Say why it is exciting. Explain how it might help the OP, or
anyone else.
On 10/04/2024 20:44, Chris M. Thomasson wrote:
The OP needs a deep read of the chaos lib:
https://github.com/rofl0r/chaos-pp
Might help... ? ;^)
I think more people would respond to your posts if you actually included content, rather than just random links and smilies.
Assume that no one here will ever click on a youtube link - then you
clearly don't need to post them.
Assume that no one will click on any random webpage link, or even to
known sites like github, unless there's plenty of information in the
posts to make it clear why the linked software is relevant.
You do a lot of interesting programming, have interesting ideas, and are energetic about sharing them and helping people. That's all great. But you could do so much better at getting your thoughts across.
So if you don't mind - please try again. Tell us what "the chaos lib" is. Say why it is exciting. Explain how it might help the OP, or
anyone else.
On 4/10/2024 12:29 PM, David Brown wrote:
On 10/04/2024 20:44, Chris M. Thomasson wrote:
The OP needs a deep read of the chaos lib:
https://github.com/rofl0r/chaos-pp
Might help... ? ;^)
I think more people would respond to your posts if you actually
included content, rather than just random links and smilies.
Assume that no one here will ever click on a youtube link - then you
clearly don't need to post them.
Assume that no one will click on any random webpage link, or even to
known sites like github, unless there's plenty of information in the
posts to make it clear why the linked software is relevant.
You do a lot of interesting programming, have interesting ideas, and
are energetic about sharing them and helping people. That's all
great. But you could do so much better at getting your thoughts across.
So if you don't mind - please try again. Tell us what "the chaos lib"
is. Say why it is exciting. Explain how it might help the OP, or
anyone else.
It is a preprocessor library with a lot of interesting fancy macros.
Iirc, the chaos preprocessor library is used in Boost.
On 10/04/2024 20:29, David Brown wrote:[...]
On 10/04/2024 20:44, Chris M. Thomasson wrote:
The OP needs a deep read of the chaos lib:
https://github.com/rofl0r/chaos-pp
I've seen lots of github projects and this is poor. But then, I don't
know if this was ever meant to be seen like this; maybe it is just data referenced by another project. Or you need special tools to view.
There are, I understand, good reasons based upon how macro expansion
works why this solution is necessary, but even when I was a lot younger
I had trouble understanding those reasons.
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
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 919 |
Nodes: | 10 (1 / 9) |
Uptime: | 49:20:34 |
Calls: | 12,183 |
Calls today: | 3 |
Files: | 186,524 |
Messages: | 2,236,159 |