13.07.2015 Views

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>ARM</strong> <strong>User</strong> <strong>Guide</strong>PRE02-CMacro replacement lists should be parenthesizedMacro replacement lists should be parenthesized to protect any lower-precedence operatorsfrom the surrounding expression. The example below is syntactically correct, although the!= operator was omitted. Enclosing the constant -1 in parenthesis will prevent the incorrectinterpretation and <strong>for</strong>ce a compiler error:#define EOF -1 // should be (-1)int getchar(void);void f(void){if (getchar() EOF) // != operator omitted{/* ... */}}PRE10-CPRE11-CWrap multi-statement macros in a do-while loopWhen multiple statements are used in a macro, enclose them in a do-while statement, sothe macro can appear safely inside if clauses or other places that expect a single statementor a statement block. Braces alone will not work in all situations, as the macro expansion istypically followed by a semicolon.Do not conclude a single statement macro definition with a semicolonMacro definitions consisting of a single statement should not conclude with a semicolon. Ifrequired, the semicolon should be included following the macro expansion. Inadvertentlyinserting a semicolon can change the control flow of the program.19.2. Declarations and Initialization (DCL)DCL30-CDCL31-CDeclare objects with appropriate storage durationsThe lifetime of an automatic object ends when the function returns, which means that apointer to the object becomes invalid.Declare identifiers be<strong>for</strong>e using themThe ISO C90 standard allows implicit typing of variables and functions. Because implicitdeclarations lead to less stringent type checking, they can often introduce unexpected anderroneous behavior or even security vulnerabilities. The ISO C99 standard requires typeidentifiers and <strong>for</strong>bids implicit function declarations. For backwards compatibility reasons,the <strong>VX</strong>-<strong>toolset</strong> C compiler assumes an implicit declaration and continues translation afterissuing a warning message (W505 or W535).856

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

Saved successfully!

Ooh no, something went wrong!