diff --git a/glib/glib-private.h b/glib/glib-private.h index dae496bfd..e96a73fb6 100644 --- a/glib/glib-private.h +++ b/glib/glib-private.h @@ -63,6 +63,18 @@ void __lsan_ignore_object (const void *p) __attribute__ ((weak)); #endif +/** + * G_CONTAINER_OF: + * @ptr: a pointer to a member @field of type @type. + * @type: the type of the container in which @field is embedded. + * @field: the name of the field in @type. + * + * Casts away constness of @ptr. + * + * Returns: a pointer to the container, so that "&(@container)->field == (@ptr)" holds. + */ +#define G_CONTAINER_OF(ptr, type, field) ((type *) G_STRUCT_MEMBER_P (ptr, -G_STRUCT_OFFSET (type, field))) + /* * g_leak_sanitizer_is_supported: *