sizeof single struct member in C

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

    Use a preprocessor directive, i.e. #define:

    #define TEXT_LEN 255
    
    typedef struct _parent
    {
      float calc ;
      char text[TEXT_LEN] ;
      int used ;
    } parent_t ;
    
    typedef struct _child
    {
      char flag ;
      char text[TEXT_LEN] ;
      int used ;
    } child_t ;
    

提交回复
热议问题