back

by AlexeyBrin·9y ago·view on hn ↗
This mimics C++ vector, e.g.:

    vector<int> vec(5);
    vec.push_back(11);
    vec.push_back(12);
Now you have in vec:

    0, 0, 0, 0, 0, 11, 12
But your suggestion is better from an API point of view.
2 comments
PS please note that there is no memset nor any other mean to zero initialize the elements. So the code appears to have a bug anyway.
Correct, this is a bug. calloc will better mimic the way C++ std::vector works.
Oh... thanks! I was not aware.