sizeof single struct member in C

后端 未结 9 2218
礼貌的吻别
礼貌的吻别 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 18:06

    c++ solution:

    sizeof(Type::member) seems to be working as well:

    struct Parent
    {
        float calc;
        char text[255];
        int used;
    };
    
    struct Child
    {
        char flag;
        char text[sizeof(Parent::text)];
        int used;
    };
    

提交回复
热议问题