sizeof single struct member in C

后端 未结 9 2193
礼貌的吻别
礼貌的吻别 2020-11-30 17:13

I am trying to declare a struct that is dependent upon another struct. I want to use sizeof to be safe/pedantic.

typedef struct _parent
{
  floa         


        
9条回答
  •  旧巷少年郎
    2020-11-30 17:49

    You are free to use FIELD_SIZEOF(t, f) in the Linux kernel. It's just defined as following:

    #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
    

    This type of macro is mentioned in other answers. But it's more portable to use an already-defined macro.

提交回复
热议问题