mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
Merge branch 'sizeof-member' into 'master'
Add and use g_sizeof_member() macro See merge request GNOME/glib!1333
This commit is contained in:
@@ -1096,4 +1096,18 @@
|
||||
|
||||
#endif /* __GI_SCANNER__ */
|
||||
|
||||
/**
|
||||
* G_SIZEOF_MEMBER:
|
||||
* @struct_type: a structure type, e.g. #GOutputVector
|
||||
* @member: a field in the structure, e.g. `size`
|
||||
*
|
||||
* Returns: the size of @member in the struct definition without having a
|
||||
* declared instance of @struct_type.
|
||||
*
|
||||
* Since: 2.64
|
||||
*/
|
||||
#define G_SIZEOF_MEMBER(struct_type, member) \
|
||||
GLIB_AVAILABLE_MACRO_IN_2_64 \
|
||||
sizeof (((struct_type *) 0)->member)
|
||||
|
||||
#endif /* __G_MACROS_H__ */
|
||||
|
@@ -50,6 +50,13 @@ test_alignof_fallback (void)
|
||||
check_alignof (struct { char a; int b; });
|
||||
}
|
||||
|
||||
static void
|
||||
test_struct_sizeof_member (void)
|
||||
{
|
||||
G_STATIC_ASSERT (G_SIZEOF_MEMBER (struct { char a; int b; }, a) == sizeof (char));
|
||||
g_assert_cmpint (G_SIZEOF_MEMBER (struct { char a; int b; }, b), ==, sizeof (int));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
@@ -58,6 +65,7 @@ main (int argc,
|
||||
|
||||
g_test_add_func ("/alignof/fallback", test_alignof_fallback);
|
||||
g_test_add_func ("/assert/static", test_assert_static);
|
||||
g_test_add_func ("/struct/sizeof_member", test_struct_sizeof_member);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user