How to replicate vector in c?

后端 未结 6 1049
一生所求
一生所求 2020-11-29 19:48

In the days before c++ and vector/lists, how did they expand the size of arrays when they needed to store more data?

6条回答
  •  有刺的猬
    2020-11-29 20:19

    You can use "Gena" library. It closely resembles stl::vector in pure C89.

    From the README, it features:

    • Access vector elements just like plain C arrays: vec[k][j];
    • Have multi-dimentional arrays;
    • Copy vectors;
    • Instantiate necessary vector types once in a separate module, instead of doing this every time you needed a vector;
    • You can choose how to pass values into a vector and how to return them from it: by value or by pointer.

    You can check it out here:

    https://github.com/cher-nov/Gena

提交回复
热议问题