EasyGUI
lc-switch.h File Reference

Go to the source code of this file.

Macros

#define MY_CAT(x, y)   MY_CAT2(x, y)
 
#define MY_CAT2(x, y)   x##y
 
#define LC_INIT(s)   s = 0;
 
#define LC_RESUME(s)   switch(s) { case 0:
 
#define LC_SET(s)   s = (unsigned short)MY_CAT(__LINE__, U); case (unsigned short)MY_CAT(__LINE__, U):
 
#define LC_END(s)   }
 

Typedefs

typedef unsigned short lc_t
 

Detailed Description

Implementation of local continuations based on switch() statment

Author
Adam Dunkels adam@.nosp@m.sics.nosp@m..se

This implementation of local continuations uses the C switch() statement to resume execution of a function somewhere inside the function's body. The implementation is based on the fact that switch() statements are able to jump directly into the bodies of control structures such as if() or while() statmenets.

This implementation borrows heavily from Simon Tatham's coroutines implementation in C: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html