The One-Letter Nested Function - a sample article for some kind of

bearophile bearophileHUGS at lycos.com
Fri Mar 9 07:36:39 PST 2012


Jos van Uden:

> On 13-2-2012 15:14, bearophile wrote:
>> Where possible it's good to add "static" to nested functions:
>
> Why?

For optimization, to be sure there's no closure allocation or a 
second pointer. But also for code correctness, because static 
functions can't use automatic variables defined in the enclosing 
function. This makes the code simpler to understand (the pure 
attribute has a similar purpose, you are sure your global 
function is not using global mutable variables).

Bye,
bearophile


More information about the Digitalmars-d mailing list