4 ms·
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 ar
by CardenB 12y ago
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.
- Snaipe 12y agoI'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 (?)
- asveikau 12y ago> 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.
- nanofortnight 12y agoYou don't get RAII in standard C. This code uses the GCC-specific cleanup attribute to emulate RAII.
- tormeh 12y agoIt 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.
- ANTSANTS 12y ago> 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/1a7bc6bb8767d6464e3ed7f1887398bfbd62dc3c:libco https://gitorious.org/bsnes/bsnes/source/1a7bc6bb8767d6464e3...
- tormeh 12y agoGreen threads on multiple POSIX threads in portable C. That's when things get complicated.