> I think if you have objects and a reference-counting GC already this problem is pretty easy, but I assume the C programmers don't want that for performance or portability or some other reason.
Uh. Every large C code base I've worked with has had this in some form, usually fairly pervasively. I've mentioned glib as a library that exercises this heavily. In the Windows world this would also include COM. Kernel mode stuff on various platforms tends to do a lot of refcounting as well.
Note that "reference counted object" is just a fancy word for "struct with an integer" - I feel like your phrases like "if you have objects" and "GC" strikes me as confusing this with other features in other languages, a sign that we're not entirely talking about the same thing.
Edit after more time spent away from it: I guess to restate the original comment, what I was trying to say is that to an experienced C programmer closures don't make anything "more hard" - it's just the same memory allocation strategies that you'll be dealing with anyway, and there are already well understood solutions (such as having one of your struct fields be a reference count).
I understand. I think you are right that it wouldn't make things more hard, I misunderstood that as implying that people wouldn't make memory mistakes under those conditions. So I was writing that one would require a GC to eliminate those kinds of mistakes.
I agree with you, reference counting is not something that would confuse an experienced programmer, but you do have to be aware of what's happening with your objects.
Uh. Every large C code base I've worked with has had this in some form, usually fairly pervasively. I've mentioned glib as a library that exercises this heavily. In the Windows world this would also include COM. Kernel mode stuff on various platforms tends to do a lot of refcounting as well.
Note that "reference counted object" is just a fancy word for "struct with an integer" - I feel like your phrases like "if you have objects" and "GC" strikes me as confusing this with other features in other languages, a sign that we're not entirely talking about the same thing.
Edit after more time spent away from it: I guess to restate the original comment, what I was trying to say is that to an experienced C programmer closures don't make anything "more hard" - it's just the same memory allocation strategies that you'll be dealing with anyway, and there are already well understood solutions (such as having one of your struct fields be a reference count).