> The generated code will look something like this excerpt: > 26a: 0e 94 3b 01 call 0x276 > 26e: 0c 94 4e 48 jmp 0x909c > 00000276 <main>: > 276: ff cf rjmp .-2 > > Leaving out the return statement (as is commonly done) produces the > same result and no compiler warnings. One thing I want to get to ASAP is seeing the generated asm code! >> Does C (or Winavr) init a declared variable to some >> defined state ALWAYS, or do I have to? > Simply stated, the C standard requires a compiler to initialize > statically allocated variables to zero. Consequently, if you define > a variable outside of a function (or inside a function with the > static attribute) it is guaranteed to be initialized to zero in the > absence of an explicit initialization. No such guarantee is made > for dynamically allocated variables, i.e., those defined within a > function but not having the static attribute. Ok, that makes sense, but it conflicts with other input I've been given. I do understand that it is always safe if I manually init the variables, and that might be "best practice" on an unconstrained or lightly constrained system, but I want to definitely know one way or the other what's happening under the hood. In ASM, I typically pave all SRAM to 0 just before launching main. I figure that this will at least start me in a known state, and either allow things to work (99-> 100% of the time), or break 100% of the time, as opposed to having ram contain random data. >There is no longer a Flash size penalty for explicit zero initialization of variables. Ok, and I like that, but that's compiler-specific. Given that I'm just starting out, I'm trying to be very careful on what I accept as "True"
Message
Re: [AVR-Chat] Re: Finally, really, actually, starting off with C
2009-01-07 by David VanHorn
Attachments
- No local attachments were found for this message.