Path: chuka.playstation.co.uk!news From: James Russell 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: Fri, 17 Jul 1998 12:06:57 +0100 Organization: Sony Computer Entertainment Europe Lines: 30 Message-ID: <35AF3051.CBD1D9D@scee.sony.co.uk> References: <35AC71D4.AA79EB4A@easynet.co.uk> <35AD10B6.153EE9C5@compuserve.com> <35AD2E8E.DEF2C169@nospam.easynet.co.uk> <35ADFF08.A310D245@easynet.co.uk> <35AE05C6.489D09F9@scee.sony.co.uk> NNTP-Posting-Host: camfw01.millennium.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.5b1 [en] (Win95; I) X-Accept-Language: en Xref: chuka.playstation.co.uk scee.yaroze.beginners:425 scee.yaroze.programming.codewarrior:308 scee.yaroze.programming.2d_graphics:449 Toby Hutton wrote: > Ok. Hrmm. I had my OT defined locally in main() originally, crashed, > made it static, everything worked. So the 'life' of the variable had > nothing to do with it - I assumed it must've been too big. I'm right > in my case, aren't I? Whoops! I really should read the message before responding... :O) I replied: > Well, there's a conflict of definition here - when I said "the time spent inside the function", > I meant the time between when you enter the function and return from the function. Function > calls made from that function are included in this time. Since you never return from the main() > function until you exit the program, the time spent inside the main() function is equal to the > life of the program! This is true, but didn't answer your question. When you call a function with local variables, the compiler will try to allocate space on the stack for them, and if the stack isn't big enough, kaboom, a crash. However, defining a variable as 'static' inside a function tells the compiler to allocate space for it (once) on the heap, not the stack, which is why your program worked when you defined it 'static'. Thanks to Patrik Buckau for pointing out my mistake. Cheers, James -- == James_Russell@scee.sony.co.uk +44 (171) 447-1626 == Developer Support Engineer - Sony Computer Entertainment Europe Two elephants fell off a cliff. Boom Boom.