Re:Banned C standard library functions in Git source code
by mlyle on Sunday August 25, 2019 @11:28AM
(#20793486)
You can build coroutines from them, too, which is really cool and useful.
[ Parent
| on HN ]
Re:Banned C standard library functions in Git source code
by thechao on Sunday August 25, 2019 @01:22PM
(#20794149)
I did! And the ergonomics are dreadful!
Re:Banned C standard library functions in Git source code
by yongjik on Sunday August 25, 2019 @04:59PM
(#20795548)
I don't know why I still remember these, but if you need to build coroutines in C, ucontext.h might be a better tool:
https://pubs.opengroup.org/onlinepubs/7908799/xsh/ucontext.h...
Re:Banned C standard library functions in Git source code
by anfilt on Sunday August 25, 2019 @07:19PM
(#20796288)
Those are deprecated.
Re:Banned C standard library functions in Git source code
by thomasjames on Sunday August 25, 2019 @03:47PM
(#20795064)
I had only seen them in the context of userspace threading. I wonder what mainstream libs use them. Do you know of any?
Re:Banned C standard library functions in Git source code
by fucking_tragedy on Sunday August 25, 2019 @05:15PM
(#20795644)
Generators are a subset of coroutines, and coroutines are useful in lexing and parsing.
Re:Banned C standard library functions in Git source code
by thomasjames on Monday August 26, 2019 @10:34AM
(#20800190)
Whoops, I meant that use set/longjmp() to implement coroutines. My wording in retrospect was super unclear. Sorry!
Re:Banned C standard library functions in Git source code
by vasama on Sunday August 25, 2019 @11:56AM
(#20793631)
I think you mean fibers, and no you can't.
Re:Banned C standard library functions in Git source code
by tlb on Sunday August 25, 2019 @12:04PM
(#20793677)
Here is an implementation of coroutines on top of setjmp/longjmp: https://fanf.livejournal.com/105413.html
Re:Banned C standard library functions in Git source code
by superpermutat0r on Sunday August 25, 2019 @01:19PM
(#20794127)
How does it work for arbitrary arguments? What about function pointers. What about calling a coroutine inside a coroutine?
It also has a stack managed in runtime. I'm not sure that would work for any other application than the fun example here.
Re:Banned C standard library functions in Git source code
by vasama on Sunday August 25, 2019 @12:15PM
(#20793754)
Looks more like an implementation of undefined behaviour to me.
Re:Banned C standard library functions in Git source code
by dang on Sunday August 25, 2019 @02:26PM
(#20794591)
"Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something."
Re:Banned C standard library functions in Git source code
by monocasa on Sunday August 25, 2019 @12:24PM
(#20793796)
The underlying implementations define the behavior here very well.
Re:Banned C standard library functions in Git source code
by fanf2 on Sunday August 25, 2019 @04:03PM
(#20795177)
Well, I would not go that far. My coroutine hack relies on “unwarranted chumminess with the implementation” (http://c-faq.com/struct/structhack.html) and there are lots of incidental things that can break it. It is best treated as an example of the principles of thread switching and stack allocation.