Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: Finally, really, actually, starting off with C

2009-01-07 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "David VanHorn" <microbrix@...> 
wrote:
> He assures me that GCC does not init variables automatically.
If your question was specifically about statically allocated 
variables, then he knows not of what he speaks (at least in this 
regard).  If you weren't clear as to the storage class, he might 
have assumed that you were talking about dynamically allocated 
variables in which case he is right.

You can prove this easily with this small program:

int myVar1;
int myVar2;
int
main(void)
{
  myVar2 = myVar1 + 1;
  for(;;)
    ;
}

Compile and link this (for any AVR) and then go look at the .lss 
file.  If you follow the execution flow from address 0, you'll see 
it eventually get to some code that looks like that shown below 
before it gets to main().  If you follow the execution, you'll see 
it explicitly zeroing out the two statically defined variables.

0000009e <__do_clear_bss>:
  9e:	11 e0       	ldi	r17, 0x01
  a0:	a0 e0       	ldi	r26, 0x00
  a2:	b1 e0       	ldi	r27, 0x01
  a4:	01 c0       	rjmp	.+2

000000a6 <.do_clear_bss_loop>:
  a6:	1d 92       	st	X+, r1

000000a8 <.do_clear_bss_start>:
  a8:	a4 30       	cpi	r26, 0x04
  aa:	b1 07       	cpc	r27, r17
  ac:	e1 f7       	brne	.-8
  ae:	0e 94 5d 00 	call	0xba
  b2:	0c 94 67 00 	jmp	0xce

000000ba <main>:
  ba:	80 91 02 01 	lds	r24, 0x0102

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.