Would I?

It's a common pattern in C libraries to pass a void pointer to callbacks, and allow the caller of the library to hand in a pointer which is then passed on to the callback.

And that's a rather sane design in a language without closures, because otherwise the the callback can't obtain additional information about the caller (except for globals, which makes rekursive calls dangerous to impossible).

Other popular design decision include a hidden, global state variable (same problem with reentrancy), or omitting callbacks altogether (might work for a directory traversal library like File::Find, but would be exceptionally painful for a GUI toolkit).


In reply to Re^4: Pass an "extra' variable to Find::File subroutine by moritz
in thread Pass an "extra' variable to Find::File subroutine by timtowtdi

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.