Path: chuka.playstation.co.uk!news From: "pal" hotmail.com> Newsgroups: scee.yaroze.beginners Subject: static variables Date: 31 Oct 1999 23:57:47 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 24 Message-ID: <01bf23f9$82197ac0$429124c3@pal-s-omnibook> References: <7vhr5g$4g31@chuka.playstation.co.uk> <7vi161$a6n2@chuka.playstation.co.uk> NNTP-Posting-Host: Aubervilliers-2-66.club-internet.fr X-Newsreader: Microsoft Internet News 4.70.1155 Nathan Miller wrote : >I've recently been reading about using 'static' variables to 'move >them off the stack' but I'm lost as to what it means. Variables declared in a function body are allocated on the stack when the function is entered, unless you specify otherwise. If you wish so, you can force them to go in registers ("register" modifier) for faster access, or to be global ("static" modifier) so that they're allocated once only before the program starts. When a variable is declared "static", it behaves exactly as if it were declared outside the function (scope aside). There's no more need for allocating it on the stack every time the function is entered - so execution time is gained. Be aware however that the function must not be called again before it ends (well, technically it can, but you must manage to avoid it corrupting its static variables) - that means, no recursion and no parallelism. Be careful with initialisation too. pal