Earlier quoted context omitted.
That link seems to be broken? Nothing opens when I click it.
http://fdiv.net/2015/10/08/emulating-defer-c-clang-or-gccblo... The original link works.
Show HN: A simple garbage collector for C
21–30 of 62 posts
Re: Show HN: A simple garbage collector for C
#22I just wish C had something like defer in go, That would cover most cases.
Defer can be emulated with the block extensions of Clang and GCC [0], though I'm not sure how much I'd like to see something like that in a codebase. [0] https://web.archive.org/web/20180426195701/http://fdiv.net/2...
Re: Show HN: A simple garbage collector for C
#23I just wish C had something like defer in go, That would cover most cases.
I know that's not directly what you're asking for, but I found the other day that "C++ Core Guidelines" have a helper library "GSL_util" that provide something similar to Go's defer. The implementation is very simple, it's just using a class for its destructor: template class final_act { public: explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {} final_act(final_act&& other) noexcept : f_(std::move(…
Re: Show HN: A simple garbage collector for C
#24Earlier quoted context omitted.
Defer can be emulated with the block extensions of Clang and GCC [0], though I'm not sure how much I'd like to see something like that in a codebase. [0] https://web.archive.org/web/20180426195701/http://fdiv.net/2...
There's also __attribute__ ((__cleanup__( ))) which can be used to implement RAII in C.
Re: Show HN: A simple garbage collector for C
#25I just wish C had something like defer in go, That would cover most cases.
Re: Show HN: A simple garbage collector for C
#26My (very surface level) understanding was always the trade off for the increased manual effort of using C - manual memory management being one example - was that you could tailor your solution exactly to your usecase for increased performance / lower resource use.
If you're going for a garbage collector, why not also benefit from some of the increased language power/features of a higher level language?
Re: Show HN: A simple garbage collector for C
#27I just wish C had something like defer in go, That would cover most cases.
Re: Show HN: A simple garbage collector for C
#28Just out of interest for people not familiar with C, latest goings on there etc, what's the usecase where you'd want a garbage collector in C? My (very surface level) understanding was always the trade off for the increased manual effort of using C - manual memory management being one example - was that you could tailor your solution exactly to your usecase for increased performance / lower resource use. If you're go…
Re: Show HN: A simple garbage collector for C
#29Just out of interest for people not familiar with C, latest goings on there etc, what's the usecase where you'd want a garbage collector in C? My (very surface level) understanding was always the trade off for the increased manual effort of using C - manual memory management being one example - was that you could tailor your solution exactly to your usecase for increased performance / lower resource use. If you're go…
> The original motivation for gc is my desire to write my own LISP in C, entirely from scratch - and that required garbage collection.
Another reason would be in platforms where you cannot run the language of your choice (because lack of implementations of JVM / Python / whatever), although those would maybe not allow malloc either.
Re: Show HN: A simple garbage collector for C
#30Earlier quoted context omitted.
There's also __attribute__ ((__cleanup__( ))) which can be used to implement RAII in C.
That's exactly what this uses. It just hides it inside a syntax that is more similar to what Go uses.
Regarding its use in the wild, I've encountered it exactly once, in the lastpass-cli (available on github). I personally wouldn't consider using it for one of my projects because it's too nonstandard, however I suppose that for a security-sensitive application it might reduce the likelihood of messing error handling and leaking things all over the place. That being said using non-standard features might also make it more likely for a contributor to misunderstand what the code does precisely and introduce a problem.