Re:Show HN: Smart pointers for the C programming language
by CardenB on Wednesday January 14, 2015 @12:02PM
(#8887468)
Forgive my ignorance, I'm still a bit of a beginner. Why is this particularly impressive? Has no one done smart pointers well for C? Smart pointers have been around a while, I thought there would be a ton of libraries for this by now.
[ Parent
| on HN ]
Re:Show HN: Smart pointers for the C programming language
by tormeh on Wednesday January 14, 2015 @12:19PM
(#8887590)
It is pretty impressive, actually. C, in general, does not have nice things. And it seems like this is on purpose. I think you're supposed to use C++ if you want nice things on top of C. That said, I've tried making green threads for C and it was a nightmare. I got something working though, so it's possible, but still a nightmare.
Re:Show HN: Smart pointers for the C programming language
by ANTSANTS on Wednesday January 14, 2015 @01:58PM
(#8888242)
> That said, I've tried making green threads for C and it was a nightmare. I got something working though, so it's possible, but still a nightmare.
By green threads, do you mean coroutines, or something more complicated? Try the libco library, it implements them in under a hundred lines of C + a small bit of assembly per architecture: https://gitorious.org/bsnes/bsnes/source/1a7bc6bb8767d6464e3...
Re:Show HN: Smart pointers for the C programming language
by tormeh on Thursday January 15, 2015 @09:57AM
(#8892737)
Green threads on multiple POSIX threads in portable C. That's when things get complicated.
Re:Show HN: Smart pointers for the C programming language
by nanofortnight on Wednesday January 14, 2015 @12:06PM
(#8887490)
You don't get RAII in standard C. This code uses the GCC-specific cleanup attribute to emulate RAII.
Re:Show HN: Smart pointers for the C programming language
by Snaipe on Wednesday January 14, 2015 @12:07PM
(#8887503)
I've only been actively programming in C for the past three years, so I'm not that much informed either, but from my researches on the subject, I haven't seen any.
The probable reason behind this is that most people programming in C wanting automatic memory management will use the Boehm-Demers-Weiser garbage collector (?)
Re:Show HN: Smart pointers for the C programming language
by asveikau on Wednesday January 14, 2015 @01:07PM
(#8887922)
> The probable reason behind this is that most people programming in C wanting automatic memory management will use the Boehm-Demers-Weiser garbage collector
The main reason behind it is this is not C.