Re: [AVR-Chat] Finally, really, actually, starting off with C
2009-01-07 by subscriptions@aeolusdevelopment.com
David VanHorn Wrote >> Global and static variables will always be auto-initialized to zero >> (according to the docs I've read), you'll need to initialize locals >> yourself if you care about their initial state (which you should). The >> compiler will not remove an unnecessary init. You are correct, doing it >> yourself will use up code space. > >While I was waiting, I asked one of the software guys here during lunch. >He assures me that GCC does not init variables automatically. >It allocates space for them, but does not init unless the init is >written by me into the declaration as: > >char i=0; > >I left my K+R at home.. >Embedded C and the Atmel AVR says that "Global variables are TYPICALLY >(caps mine) cleared when main is started. > >"typically" does not leave me with a warm fuzzy feeling.... Global and static variables are required to be initialized to zero for standard C implementations if they are not explicitly initialized to something else. It has been quite a while since I've seen an implementation that does not (the last one was a PIC compiler I believe). Some compilers do have an option of turning off the initialization in their switches and most compilers do the init in their startup code so it's easy to comment out the init. I would recommend against doing that unless you have a really, really, really good reason. The loop to do the init is usually small (a few bytes) and the time taken to do the memory clearing is short. Robert ------------------------------------ Yahoo! Groups Links -------------------------------------------------------------------- mail2web LIVE – Free email based on Microsoft® Exchange technology - http://link.mail2web.com/LIVE