News for hackers. Stuff that matters.
Re:Why Rust closures are somewhat hard by naasking on Monday September 10, 2018 @05:25PM (#17955341)
You can copy the pointers, but that doesn't make it safe because you could have pointers to stack values.
Re:Why Rust closures are somewhat hard by geezerjay on Monday September 10, 2018 @05:44PM (#17955478)
I don't see how that's relevant. If a developer sets a pointer to point to a stack object then copying the pointer, whether manually or through a hypothetical closure, doesn't change nor create the problem.
Re:Why Rust closures are somewhat hard by naasking on Monday September 10, 2018 @06:38PM (#17955777)
The problem is returning a closure that points to a stack variable that's now out of scope.
Re:Why Rust closures are somewhat hard by geezerjay on Tuesday September 11, 2018 @01:24AM (#17957368)
It isn't. The hypothetical problem was setting a pointer to a stack variable. That's a no-no from the start, and adding hypothetical closures to the mix changes nothing.
Re:Why Rust closures are somewhat hard by samnardoni on Tuesday September 11, 2018 @02:46AM (#17957632)
Having a pointer to a stack variable is fine, as long as the stack variable lives longer than the closure.
Re:Why Rust closures are somewhat hard by naasking on Tuesday September 11, 2018 @08:21AM (#17959018)
Right, so your original claim about properly cleaning up is not the only problem with closures in C. There are quite a few hazards actually.
Re:Why Rust closures are somewhat hard by geezerjay on Tuesday September 11, 2018 @11:24AM (#17960558)
> Right, so your original claim about properly cleaning up is not the only problem with closures in C.

Your comment makes no sense. OP stated that your hypothetical problem isn't even a problem if the developer knows what he is doing, and your take from that is that there are more problems?

Re:Why Rust closures are somewhat hard by naasking on Tuesday September 11, 2018 @12:58PM (#17961419)
The original poster said the trouble was cleaning up after the closure is no longer needed. That's clearly not the case as this thread has covered. I thought the previous poster was the original poster, so just replace "your original claim" with "the original claim".