02.03.2014 Views

BSP Developer's Guide

BSP Developer's Guide

BSP Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8<br />

Writing Portable C Code<br />

8.1.5 Other Issues<br />

Follow Strict ANSI Compilation<br />

Compilation units should be compiled with strict ANSI protocols in effect. This<br />

requires detailed prototype declarations. For the GNU compiler system, the<br />

compiler flags should include the following:<br />

-Wall -W -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes<br />

Remove Compiler Warnings<br />

8<br />

Portable code must be as free of warnings as possible. Apply the strictest possible<br />

code checking and fix all reported warning situations. Compilers identify<br />

non-portable code issues well when doing error checking.<br />

Avoid Use of Casts<br />

Each and every cast represents a potential error. It is a common practice to use a<br />

cast to fix warnings reported by the compiler. However, each instance must be<br />

examined carefully to insure that a cast is the appropriate action. Often a warning<br />

indicates an actual error in argument passing that must be corrected. Using a cast<br />

overrides the compiler’s ability to detect an actual error in data usage that may<br />

prove to be significant.<br />

Avoid inline Keyword<br />

The C inline keyword is to be avoided until the GNU and Diab compilers can<br />

implement it in a consistent manner. The current ANSI Specification, C99, does call<br />

for an inline keyword. However, at this time, neither compiler fully supports this<br />

specification. Although each accepts the inline keyword, there are subtle but<br />

significant differences in the implementation. An update to this document will be<br />

issued when support for the inline keyword is available.<br />

165

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

Saved successfully!

Ooh no, something went wrong!