nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.84k stars 7.72k forks source link

Documentation added to Dynamic array initialization with known initial size #1333

Closed BlazesRus closed 1 year ago

BlazesRus commented 2 years ago

Documentation added to Dynamic array to make easier for someone to know how to use dynamic array macro

nothings commented 2 years ago

That doesn't work, as the array pointer needs to be NULL when you call arrsetlen, not undefined.

BlazesRus commented 2 years ago

Fixed it changed it to: //Initialyze array with struct ElementType* ArrayName = NULL; //arrsetlen(ArrayName, num_elems); //Equavalent to ANSI C99/C89 version of struct ElementType ArrayName[num_elems];

nothings commented 2 years ago

I'm not sure how much value that explanation adds, as the standard way to create an array of N elements is push the N elements individually with arrput; arrsetlen works and is more efficient, but I'm not sure it's worth adding explicitly. Even if we did want to add this, that's probably not the right place for it, it should appear in the documentation section starting at line 69, either as an introductory thing or as part of the documentation for arrsetlen at line 134.

rygorous commented 1 year ago

I don't think we want to take this, closing.