Closure (computer programming): Difference between revisions

Content deleted Content added
m Closure-like constructs: WP:LINK 1st instances. List alphabetize. MOS:FIRSTABBR clarify, define before WP:ABBR in parentheses.
Add missing "s" to sometimes
Line 329:
 
=== Callbacks (C) ===
Some [[C (programming language)|C]] libraries support [[Callback (computer programming)|callbacks]]. This is ometimessometimes implemented by providing two values when registering the callback with the library: a function pointer and a separate <code>void*</code> pointer to arbitrary data of the user's choice. When the library executes the callback function, it passes along the data pointer. This enables the callback to maintain state and to refer to information captured at the time it was registered with the library. The idiom is similar to closures in functionality, but not in syntax. The <code>void*</code> pointer is not [[Type safety|type safe]] so this C idiom differs from type-safe closures in C#, Haskell or ML.
 
Callbacks are used extensively in [[graphical user interface]] (GUI) [[widget toolkit]]s to implement [[event-driven programming]] by associating general functions of graphical widgets (menus, buttons, check boxes, sliders, spinners, etc.) with application-specific functions implementing the specific desired behavior for the application.