std-aux: move nm_offsetof_end() to std-aux and add nm_offsetof()

In std-aux, we cannot use G_STRUCT_OFFSET(). I guess, we could use
offsetof() directly. Instead, add an nm_offsetof() macro. This requires
<stddef.h>.
This commit is contained in:
Thomas Haller 2021-07-30 10:35:18 +02:00
parent 91a36478f6
commit 194e29d0dc
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 9 additions and 4 deletions

View file

@ -43,10 +43,6 @@
/*****************************************************************************/
#define nm_offsetofend(t, m) (G_STRUCT_OFFSET(t, m) + sizeof(((t *) NULL)->m))
/*****************************************************************************/
#define gs_free nm_auto_g_free
#define gs_unref_object nm_auto_unref_object
#define gs_unref_variant nm_auto_unref_variant

View file

@ -10,6 +10,7 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stddef.h>
/*****************************************************************************/
@ -222,6 +223,14 @@ typedef uint64_t _nm_bitwise nm_be64_t;
#define NM_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
/*****************************************************************************/
#define nm_offsetof(t, m) offsetof(t, m)
#define nm_offsetofend(t, m) (nm_offsetof(t, m) + sizeof(((t *) NULL)->m))
/*****************************************************************************/
/* This does a compile time check that "type" is a suitable C type. It either
* returns a compile time constant of 1 or it fails compilation. The point
* is only in macros to check that a macro parameter (what we might pass to