Closure (computer programming): Difference between revisions

Content deleted Content added
WP:REFerence WP:CITation parameters: updates, corrects, respaces, reorders, adds, fills, author > last + first, conform to master templates. Small WP:COPYEDITs WP:EoS: WP:TERSE, clarify, 2nd MOS:PERSON WP:YOUs fix-cut. WP:LINKs: adds, update-standardizes, needless WP:PIPEs > WP:NOPIPEs. MOS:FIRSTABBReviation clarify, define before WP:ABBR in parentheses. Cut needless carriage returns in: WP:CITations, paragraphs.
Line 355:
 
====Nested function and function pointer (C)====
With a [[GNU Compiler Collection]] (GCC) extension, a [nested function<ref>{{cite web
|url = https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
|title nested= function]Nested functions}}</ref> can be used and a function pointer can emulate closures, providing the function does not exit the containing scope. The next example is invalid because <code>adder</code> is a top-level definition (depending on compiler version, it could produce a correct result if compiled with no optimizing, i.e., at <code>-O0</code>):
 
<syntaxhighlight lang="c">