Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I strongly suspect that you misread the page.

The initial example was a caller/caller setup. That is the ideal that you'd like to achive and could with co-routines, but C doesn't have them.

The second example was callee/callee. One half there goes with one half from the first example. The point being that changing the same code from caller to callee generally makes it a lot uglier. As the code becomes more complex, the ugliness grows rapidly.

From there he went on to explain the hack that enabled him to partially get to the ideal. The hack is complex, and the result is not quite as clean you'd like, but you get back a long way towards the ideal. In particular the complications come from having to insert appropriate macros, but the structure of the code does not change at all.

As for why he does this, his PuTTY program supports several different compression/encryption options with several different protocols that require parsing. If he had to rewrite one set or the other to be clean callees, that half of the code would become unmaintainable. With his hack to emulate co-routines, he keeps both halves fairly sane.

With proper co-routines, his ideal caller/caller example is even closer to what he would get - you just need to insert "yield" at the right places in the one that you want to really be a callee.


In reply to Re^3: Easy coroutines? by tilly
in thread Easy coroutines? by fletcher_the_dog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found