0

A typical use of a function object is in writing callback functions. A callback in procedural languages, such as C, may be performed by using function pointers. Here is the sentence that confuses me:

However it can be difficult or awkward to pass a state into or out of the callback function.

In particular, I can't understand this expression: pass a state into or out of the callback function. Can you explain it to me?

closed as off-topic by Nathan Tuggy, Damkerng T., P. E. Dant, Glorfindel, Varun Nair Sep 7 '16 at 5:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question should include more details than have been provided here. Please edit to add the research you have done in your efforts to answer the question, or provide more context. See: Details, Please." – Nathan Tuggy, Damkerng T., P. E. Dant, Glorfindel, Varun Nair
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Did you look up "state"? How about "pass"? Please edit to include the research you've done for those. (You should also clarify whether the first two sentences are also part of the quote.) – Nathan Tuggy Sep 6 '16 at 20:31
  • Welcome to ELL, and thank you for your question. Our Tour and Help Center pages contain useful information on asking and answering questions. We encourage you to ask more questions! – P. E. Dant Sep 6 '16 at 20:32
0

This question is more for programming than English. A "state" is any variable, anything that can change.

"Pass a state into" -> send anything into the function, like a parameter.

"Pass a state out" -> get anything from the function, be it as a result of the function (return) or as an out parameter (like in C#).

  • thx :) god bless u – JPH Sep 6 '16 at 20:41
  • Thank you for joining us at ELL, and thank you for your answer. Our Tour and Help Center provide tips on how to write useful questions and answers. We hope you'll ask questions of your own! – P. E. Dant Sep 6 '16 at 20:54
0

This is quite technical writing about programming concepts; words such as state have specialised meaning.

Loosely speaking, state is the value of some variables at a particular moment.

The problem here is that when doing some asynchronous work the initiator of the work tells the worker

Do some work, when you have finished please call this callback function with the result

The initiator then proceeds to do other processing, it never directly "hears" the result from the worker. However the callback function will eventually get called with the worker's results, and at that point may need access to state held by the initiating process.

Very Contrived Example:

Initiator: customer X wants to buy 3 units of stuff. At this point the initiator has state such as information about the customer, and the order.

Initiator needs the price of 3 units of stuff so calls the Pricing Engine, telling it to call the PrepareInvoice function when the price is determined.

PrepareInvoice Callback function receives the price from the Pricing Engine (simply passed from the Engine as it calls the function) BUT needs the Customer information, which is state known only to the Initiator.

There are idioms in many Programming languages to allow us to solve this problem.

  • thx ;) very helpful – JPH Sep 6 '16 at 20:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.