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<strong>the</strong>y are not <strong>the</strong> same thing. For example, an array has storage space associated withit, whereas you must initialize a pointer to point to some valid space be<strong>for</strong>e accessingit.Structure / Union TypeFor whatever reasons, some beginners seem to have a lot of trouble with <strong>the</strong> structdeclaration. The basic <strong>for</strong>m isstruct [tag] { member-declaration * } [variable list];The following are valid examples of declaring a struct variable:1) struct { int junk; } var1;2) struct tag1 { int junk; } var2;3) struct tag2;struct tag2 { int junk; };struct tag2 var3;The tag is optional <strong>and</strong> is useful if you want to refer to <strong>the</strong> same struct type again(<strong>for</strong> example, you can use struct tag1 to declare more variables of that type). In C,within <strong>the</strong> same file, even if you have two identical-looking struct declarations, <strong>the</strong>yare different struct types. In <strong>the</strong> examples above, all of <strong>the</strong> structs have differenttypes, even though <strong>the</strong>ir struct types look identical.However, in <strong>the</strong> case of separate files, this rule is relaxed: if two structs have <strong>the</strong>same declaration, <strong>the</strong>n <strong>the</strong>y are equivalent. This makes sense, since in C, it isimpossible to have a single declaration to appear in more than one file. Declaring <strong>the</strong>struct in a header file still means that a separate (but identical-looking) declarationappears in each file that #include <strong>the</strong> header file.Function PrototypeIn <strong>the</strong> old days of C, it was sometimes acceptable to call a function without declaring itfirst -- everything would work correctly anyway. However, with <strong>the</strong> ImageCraft<strong>compiler</strong>s, it is important to declare a function be<strong>for</strong>e referencing it, including <strong>the</strong> typesof <strong>the</strong> function arguments. O<strong>the</strong>rwise, it is possible that <strong>the</strong> <strong>compiler</strong> will not generate<strong>the</strong> correct code. When you declare a function with a complete argument <strong>and</strong> returntype in<strong>for</strong>mation, it’s called <strong>the</strong> function prototype of <strong>the</strong> function.76

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

Saved successfully!

Ooh no, something went wrong!