29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

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.

<strong>Compiler</strong> Coding Practices<br />

5.60 New language features of C99<br />

The 1999 C99 standard introduces several new language features, including:<br />

• Some features similar to extensions to C90 offered in <strong>the</strong> GNU compiler, <strong>for</strong> example,<br />

macros with a variable number of arguments.<br />

Note<br />

The implementations of extensions to C90 in <strong>the</strong> GNU compiler are not always<br />

compatible with <strong>the</strong> implementations of similar features in C99.<br />

• Some features available in C++, such as // comments and <strong>the</strong> ability to mix declarations<br />

and statements.<br />

• Some entirely new features, <strong>for</strong> example complex numbers, restricted pointers and<br />

designated initializers.<br />

• New keywords and identifiers.<br />

• Extended syntax <strong>for</strong> <strong>the</strong> existing C90 language.<br />

A selection of new features in C99 that might be of interest to developers using <strong>the</strong>m <strong>for</strong> <strong>the</strong> first<br />

time are documented.<br />

Note<br />

C90 is compatible with Standard C++ in <strong>the</strong> sense that <strong>the</strong> language specified by <strong>the</strong> standard is<br />

a subset of C++, except <strong>for</strong> a few special cases. New features in <strong>the</strong> C99 standard mean that C99<br />

is no longer compatible with C++ in this sense.<br />

Some examples of special cases where <strong>the</strong> language specified by <strong>the</strong> C90 standard is not a subset<br />

of C++ include support <strong>for</strong> // comments and merging of <strong>the</strong> typedef and structure tag<br />

namespaces. For example, in C90 <strong>the</strong> following code expands to x = a / b - c; because /*<br />

hello world */ is deleted, but in C++ and C99 it expands to x = a - c; because everything<br />

from // to <strong>the</strong> end of <strong>the</strong> line is deleted:<br />

x = a //* hello world */ b<br />

- c;<br />

The following code demonstrates how typedef and <strong>the</strong> structure tag are treated differently<br />

between C (90 and 99) and C++ because of <strong>the</strong>ir merged namespaces:<br />

typedef int a;<br />

{<br />

struct a { int x, y; };<br />

printf("%d\n", sizeof(a));<br />

}<br />

In C 90 and C99, this code defines two types with separate names whereby a is a typedef <strong>for</strong><br />

int and struct a is a structure type containing two integer data types. sizeof(a) evaluates to<br />

sizeof(int).<br />

In C++, a structure type can be addressed using only its tag. This means that when <strong>the</strong> definition<br />

of struct a is in scope, <strong>the</strong> name a used on its own refers to <strong>the</strong> structure type ra<strong>the</strong>r than <strong>the</strong><br />

typedef, so in C++ sizeof(a) is greater than sizeof(int).<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 5-77<br />

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!