News for hackers. Stuff that matters.
Re:Emulating exceptions in C: a case study by halayli on Thursday August 27, 2015 @12:42PM (#10130502)
Exceptions are not about going from one place to another. It's about unwinding the stack properly and calling the destructors of variables on the stack. This is not a close emulation at all.
Re:Emulating exceptions in C: a case study by rwmj on Thursday August 27, 2015 @01:00PM (#10130605)
While I'm not saying this is a good idea, you can combine a pool allocator with longjmp exceptions to get an approximation of unwinding. It requires that you are very careful about structuring your code, but I once wrote a whole web server this way: http://git.annexia.org/?p=rws.git;a=tree (using: http://git.annexia.org/?p=c2lib.git;a=tree ).
Re:Emulating exceptions in C: a case study by halayli on Thursday August 27, 2015 @02:08PM (#10131023)
But sometimes it's not just memory. It can be files you need to close, or any other resource held.
Re:Emulating exceptions in C: a case study by chaz72 on Thursday August 27, 2015 @04:40PM (#10131948)
That too can be queued up, with a list of functions to call to free those resources.
Re:Emulating exceptions in C: a case study by halayli on Thursday August 27, 2015 @09:32PM (#10133246)
He was referring to a memory pool allocator. But regardless, good luck with the approach.
Re:Emulating exceptions in C: a case study by rwmj on Friday August 28, 2015 @03:36AM (#10134126)
Pool allocators can easily deal with non-memory resources. The one I wrote in c2lib could.