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
  • Please look at GCC and EW which allow this kind of notation.

    That is truly horrible.

    I've just tried a few experiments with GCC and these structures. It appears to accept it (which did surprise me), but after that it does what I would expect of it, and that's not very useful!

    I created an instance of one, set the timestamp field and then filled in the header with three bytes of 'payload' and the timestamp field got chomped.

    Nope, I'll definitely stick to the KISS principle and avoid this type of thing as much as possible.

Reply
  • Please look at GCC and EW which allow this kind of notation.

    That is truly horrible.

    I've just tried a few experiments with GCC and these structures. It appears to accept it (which did surprise me), but after that it does what I would expect of it, and that's not very useful!

    I created an instance of one, set the timestamp field and then filled in the header with three bytes of 'payload' and the timestamp field got chomped.

    Nope, I'll definitely stick to the KISS principle and avoid this type of thing as much as possible.

Children