Why use array size 1 instead of pointer?

后端 未结 6 797
滥情空心
滥情空心 2020-12-02 09:04

In one C++ open source project, I see this.

struct SomeClass {
  ...
  size_t data_length;
  char data[1];
  ...
}

What are the advantages

6条回答
  •  [愿得一人]
    2020-12-02 09:15

    The idea behind this particular thing is that the rest of data fits in memory directly after the struct. Of course, you could just do that anyway.

提交回复
热议问题