Path: chuka.playstation.co.uk!news From: Toby Hutton Newsgroups: scee.yaroze.beginners,scee.yaroze.programming.codewarrior,scee.yaroze.programming.2d_graphics Subject: Re: Still strugglin' with the basics: broken sprite code (long) Date: 16 Jul 1998 11:15:36 +1000 Organization: PlayStation Net Yaroze (SCEE) Lines: 24 Sender: thutton@TECH10 Message-ID: References: <35AC71D4.AA79EB4A@easynet.co.uk> <35AD10B6.153EE9C5@compuserve.com> <35AD2E8E.DEF2C169@nospam.easynet.co.uk> NNTP-Posting-Host: 203.103.154.235 X-Newsreader: Gnus v5.3/Emacs 19.34 Xref: chuka.playstation.co.uk scee.yaroze.beginners:415 scee.yaroze.programming.codewarrior:303 scee.yaroze.programming.2d_graphics:442 Philip Gooch writes: > But what confuses me is: Why does OTTags need to be a global if I'm only using it > in one function - InitGraphics()? Is GsOT_TAG somehow used by the OS throughout > the program and so needs to be aware of it whenever it needs it? Sorry, I'm > really dim on the low-level stuff. I'm better at algorithms - honest! The main difference between local variables and globals variables in C is their scope, obviously (ie. which functions can see them). The second biggest difference is where they're stored. Global and static variables are allocated from the heap, while locals are from the stack. The stack is also used to store parameters passed to functions and return addresses. Exhausting the stack is a Bad Thing, as function calls may misbehave, crash, hang... I honestly don't know how big the default stack is for the Yaroze - it's determined at compile time. That's why your code may work for one compiler, but not another. Basically, if you have some enormous data structures locally, make them static. But remember, they'll persist across multiple calls to the function, though this doesn't matter if you were already treating them as locals (which don't persist). -- Toby.