29.12.2014 Views

RealView Compilation Tools Compiler Reference Guide - ARM ...

RealView Compilation Tools Compiler Reference Guide - ARM ...

RealView Compilation Tools Compiler Reference Guide - ARM ...

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.

C and C++ Implementation Details<br />

Pointer subtraction<br />

The following statements apply to all pointers in C. They also apply to pointers in C++,<br />

other than pointers to members:<br />

• When one pointer is subtracted from another, the difference is the result of the<br />

expression:<br />

((int)a - (int)b) / (int)sizeof(type pointed to)<br />

• If the pointers point to objects whose alignment is the same as their size, this<br />

alignment ensures that division is exact.<br />

• If the pointers point to objects whose alignment is less than their size, such as<br />

packed types and most structs, both pointers must point to elements of the same<br />

array.<br />

5.1.4 Structures, unions, enumerations, and bitfields<br />

This section describes the implementation of the structured data types union, enum, and<br />

struct. It also discusses structure padding and bitfield implementation.<br />

See Anonymous classes, structures and unions on page 3-20 for more information.<br />

Unions<br />

When a member of a union is accessed using a member of a different type, the resulting<br />

value can be predicted from the representation of the original type. No error is given.<br />

Enumerations<br />

An object of type enum is implemented in the smallest integral type that contains the<br />

range of the enum. The storage type of an enum is the first of the following, according to<br />

the range of the enumerators in the enum:<br />

• unsigned char if not using --enum_is_int<br />

• signed char if not using --enum_is_int<br />

• unsigned short if not using --enum_is_int<br />

• signed short if not using --enum_is_int<br />

• signed int<br />

• unsigned int except C with --strict<br />

• signed long long except C with --strict<br />

• unsigned long long except C with --strict.<br />

Implementing enum in this way can reduce data size. The command-line option<br />

--enum_is_int forces the underlying type of enum to at least as wide as int.<br />

<strong>ARM</strong> DUI 0348A Copyright © 2007, 2010 <strong>ARM</strong> Limited. All rights reserved. 5-7<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!