sizeof single struct member in C

后端 未结 9 2166
礼貌的吻别
礼貌的吻别 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:42

    I am not on my development machine right now, but I think you can do one of the following:

    sizeof(((parent_t *)0)->text)
    
    sizeof(((parent_t){0}).text)
    


    Edit: I like the member_size macro Joey suggested using this technique, I think I would use that.

提交回复
热议问题