Liste des Groupes | Revenir à cl c |
On 10/04/2024 16:26, Scott Lurndal wrote:The OP needs a deep read of the chaos lib:David Brown <david.brown@hesbynett.no> writes: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!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.
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.
Les messages affichés proviennent d'usenet.