How to use zero length array in C

后端 未结 4 670
天涯浪人
天涯浪人 2021-01-14 03:39

We can initialize a struct with zero length array as specified in the link:

Zero-Length.

I\'m using the following structures:

typedef unsigne         


        
4条回答
  •  粉色の甜心
    2021-01-14 04:18

    Better to use payload[] instead of payload[0] in C99. Some of C99 compilers discourage usage of zero length array. So, in case you get an error here :

    typedef struct CommandHeader
    {
        UINT16 len;
        UINT8 payload[0];
    } CommandHeader;
    

    you can always correct it as :

    typedef struct CommandHeader
    {
        UINT16 len;
        UINT8 payload[];
    } CommandHeader;
    

提交回复
热议问题