11.07.2015 Views

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVR#endifEXTERN int clock_ticks;Then in one <strong>and</strong> only one of <strong>the</strong> source files (say, main.c), you can write#define EXTERN#include “header.h”In all o<strong>the</strong>r source files, you would just #include “header.h” without <strong>the</strong>preceding #define. Since main.c has EXTERN defined to be nothing, <strong>the</strong>n <strong>the</strong>inclusion of header.h has <strong>the</strong> effect of defining <strong>the</strong> global variable clock_ticks. Inall o<strong>the</strong>r source files, <strong>the</strong> EXTERN is exp<strong>and</strong>ed as extern, thus declaring (but notdefining) clock_ticks as a global variable <strong>and</strong> allowing it to be referenced in <strong>the</strong>source files.Use of Global Variables vs. Locals <strong>and</strong> Function ArgumentsFunctions can communicate using ei<strong>the</strong>r global variables or function arguments. Onsome processors, it is better to use global variables; on o<strong>the</strong>rs, it is better to use localvariables <strong>and</strong> arguments; <strong>and</strong> on some o<strong>the</strong>rs, it does not matter at all. The followingsummarizes <strong>the</strong> current ImageCraft <strong>compiler</strong> targets but should only be used as aguideline. You should always balance optimization needs with program maintenanceneeds.Generally, using local variables is a better choice <strong>for</strong> <strong>the</strong> Atmel AVR, TI MSP 430 <strong>and</strong>ARM targets. ImageCraft <strong>compiler</strong>s <strong>for</strong> <strong>the</strong>se targets automatically allocate localvariables to machine registers if possible <strong>and</strong> programs under <strong>the</strong>se RISC processorsrun much faster when machine registers are used. On <strong>the</strong> Motorola HC11 <strong>and</strong> HC12/S12, it is a slight win to use local variables. On <strong>the</strong> HC08/S08, it probably does notmatter at all.On some processors that we do not support, it is much better to use global variables.For example, <strong>the</strong> 8051 is such an architecture.73

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!