Coroutines in C

4    09 Jan 2016 01:00 by u/dchem

3 comments

2

Of course, this trick violates every coding standard in the book. Try doing this in your company's code and you will probably be subject to a stern telling off if not disciplinary action! You have embedded unmatched braces in macros, used case within sub-blocks, and as for the crReturn macro with its terrifyingly disruptive contents . . . It's a wonder you haven't been fired on the spot for such irresponsible coding practice. You should be ashamed of yourself.

Rule number one for professional developers: If code standards prevents you to create functional code, break those rules

0

Yep. Right after this he goes on to say that.

2

A pity. Still, at least C++ users can manage this by having their coroutine be a class member, and keeping all its local variables in the class so that the scoping is implicit.)

Don't let anyone tell you that C can't do C++. Long before C++ existed C people were already using things that mimics C++. C++ basically translates it to C code under the hood.

C++:  MyObject.Foo(int a, int b)

Becomes this. Look at the assembly output so see that.

C:  Foo(MyObject* this, int a, int b)