4 ms·
This is not garbage collection because these are stack (or statically) allocated. The "garbage" in "GC" are heap allocations. If we ignore the heap in C it doe
by kaoD 8y ago
This is not garbage collection because these are stack (or statically) allocated. The "garbage" in "GC" are heap allocations.
If we ignore the heap in C it doesn't make it a GC'd language because the concept of GC isn't even defined with no heap.
> It is entirely possible to write complex C programs using nothing but automatic variables
For a very narrow subset of "complex". As soon as dynamically-sized type is introduced you need the heap.
It's also surprisingly inefficient: suddenly all your buffers (including strings) must be as long as the largest buffer you could imagine you'd need.
Which also introduces artificial limits.
- bjourne 8y agoC has VLAs https://en.wikipedia.org/wiki/Variable-length_array https://en.wikipedia.org/wiki/Variable-length_array Apparently I suck at linking because this was the thread I was looking for: https://news.ycombinator.com/item?id=18124708 https://news.ycombinator.com/item?id=18124708 As you can see, there is no heap in C so we are free to ignore it.
- kaoD 8y agoI pretty much agree with that thread's replies, not much to add. I didn't know VLAs though (they didn't exist back in the day when I used C). Even though you still have no growable buffers/reallocation (AFAICT), I concede those open up a wider class of complex programs. Thanks for the pointer (pun intended) on VLAs, will check them out. Still no garbage collection though (and I agree with you that neither is Rust's).