On 17/10/2023 08:51, Jan Beulich wrote:
On 16.10.2023 18:49, Nicola Vetrini wrote:
On 16/10/2023 15:43, Jan Beulich wrote:
On 11.10.2023 14:46, Nicola Vetrini wrote:
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -109,13 +109,16 @@
#define offsetof(a,b) __builtin_offsetof(a,b)
+/* Access the field of structure type, without defining a local
variable */
+#define access_field(type, member) (((type *)NULL)->member)
This is not a field access, so I consider the macro misnamed.
Question
is
whether such a helper macro is needed in the first place.
+#define typeof_field(type, member) typeof(access_field(type,
member))
If this needs adding, it wants to come ...
/**
* sizeof_field(TYPE, MEMBER)
*
* @TYPE: The structure containing the field of interest
* @MEMBER: The field to return the size of
*/
-#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+#define sizeof_field(TYPE, MEMBER) sizeof(access_field(TYPE,
MEMBER))
... with a commend similar as this one has. (Or the commend could be
slightly altered to cover both).
I added access_field since it's possibly useful on its own in the
future,
but that may not be the case. Not a real field access, perhaps a
fake_access_field?
I don't like this either, I'm afraid: This isn't a fake access. Maybe
field_of() or field_of_type()? Yet at this point I'd still prefer for
this to not be a separate macro in the first place.
Jan
Ok, no problem.
--
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)