compiler: add a sizeof_field() macro

Determining the size of a field is useful when you don't have a struct
variable handy. Open-coding this is ugly.

This patch adds the sizeof_field() macro, which is similar to
typeof_field(). Existing instances are updated to use the macro.

Backports commit f18793b096e69c7acfce66cded483ba9fc01762a from qemu
This commit is contained in:
Stefan Hajnoczi 2018-07-03 01:02:46 -04:00 committed by Lioncash
parent a63e549673
commit e8b92838fe
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -28,6 +28,7 @@
#endif
#endif
#define sizeof_field(type, field) sizeof(((type *)0)->field)
static double rint( double x )
{
@ -166,6 +167,8 @@ static union MSVC_FLOAT_HACK __NAN = {{0x00, 0x00, 0xC0, 0x7F}};
#endif
#endif
#define sizeof_field(type, field) sizeof(((type *)0)->field)
/* Convert from a base type to a parent type, with compile time checking. */
#ifdef __GNUC__
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \