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 AVRExpressions <strong>and</strong> Type PromotionsSemicolon TerminationThe expression statement is one of <strong>the</strong> few statements in C that requires asemicolon termination. The o<strong>the</strong>rs are break, continue, return, goto, <strong>and</strong> dostatements. Sometimes you see things like:#define foo blah blah;...void bar() { ... };Those semicolons at <strong>the</strong> end are most likely extraneous <strong>and</strong> can possibly even causeyour program to fail subtly (to compile or to execute).lvalue <strong>and</strong> rvalueEvery expression produces a value. If <strong>the</strong> expression is on <strong>the</strong> left-h<strong>and</strong> side of anassignment, it is called an lvalue. In all o<strong>the</strong>r cases, an expression produces a rvalue.An lvalue is ei<strong>the</strong>r <strong>the</strong> name of a variable, an array element reference, a pointerdereference, or a struct/union field member; everything else is not a valid lvalue. Acommon question is why does <strong>the</strong> <strong>compiler</strong> complain about((char *)pc)++<strong>and</strong> <strong>the</strong> answer is that type cast does not produce an lvalue. Some <strong>compiler</strong>s mayaccept it as an extension, but it is not part of <strong>the</strong> st<strong>and</strong>ard C. This is an example of <strong>the</strong>correct method of incrementing a cast variable:unsigned pc;...pc = (unsigned)((char *)pc + 1);Integer ConstantsInteger constants are ei<strong>the</strong>r decimal (default), octal (starting with 0), or hexadecimal(0x or 0X). Our <strong>compiler</strong>s support <strong>the</strong> extension of using 0b as a prefix <strong>for</strong> binaryconstants. You can explicitly change <strong>the</strong> type of an integer constant by adding U/u, L/l, or combinations of <strong>the</strong>m. The type of an integer is <strong>the</strong> first type of each list in <strong>the</strong>following table that can hold <strong>the</strong> value of <strong>the</strong> constant:77

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

Saved successfully!

Ooh no, something went wrong!