This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Empty arrays in nested structures

I am porting code from ew and gcc to keil uvision arm compiler (Arm compiler 5.06 update 1 build 61).

Both ew and gcc allow me to the following:

struct header
{
    uint32_t chksum;
    uint8_t id;
    uint8_t size;   /* This many bytes follow immediately */
    uint8_t payload[]; /* Allows for easy access to the payload of variable size packets */
}

struct datapacket
{
    struct header header;
    uint64_t timestamp;
    uint8_t data[];
}

Is it possible to something similar with the arm compiler?
I have enabled the C99 option which allows for empty array declaration but it does not seem to accept that the header has the empty array member payload[].

Parents
  • struct header
    {
        uint32_t chksum;
        uint8_t id;
        uint8_t size;   /* This many bytes follow immediately */
        uint8_t payload[]; /* Allows for easy access to the payload of variable size packets */
    }
    
    struct datapacket
    {
        struct header header;
        uint64_t timestamp;
        uint8_t data[];
    }
    

    I don't think that can work - because you're saying that you have the variable-length struct header followed by timestamp and data.

    I guess what you're really looking for is to overlay timestamp and data on the payload field of header ?

    I think it would make more sense to have the struct named "header" just be the header:

    struct header
    {
        uint32_t chksum;
        uint8_t id;
        uint8_t size;   /* This many bytes follow immediately */
    }
    

    And then your datapacket has the header followed by timestamp and data:

    struct datapacket
    {
        struct header header;
        uint64_t timestamp;
        uint8_t data[];
    }
    

Reply
  • struct header
    {
        uint32_t chksum;
        uint8_t id;
        uint8_t size;   /* This many bytes follow immediately */
        uint8_t payload[]; /* Allows for easy access to the payload of variable size packets */
    }
    
    struct datapacket
    {
        struct header header;
        uint64_t timestamp;
        uint8_t data[];
    }
    

    I don't think that can work - because you're saying that you have the variable-length struct header followed by timestamp and data.

    I guess what you're really looking for is to overlay timestamp and data on the payload field of header ?

    I think it would make more sense to have the struct named "header" just be the header:

    struct header
    {
        uint32_t chksum;
        uint8_t id;
        uint8_t size;   /* This many bytes follow immediately */
    }
    

    And then your datapacket has the header followed by timestamp and data:

    struct datapacket
    {
        struct header header;
        uint64_t timestamp;
        uint8_t data[];
    }
    

Children