Download RealView Compilation Tools Compiler Reference Guide
Transcript
C and C++ Implementation Details Pointer subtraction The following statements apply to all pointers in C. They also apply to pointers in C++, other than pointers to members: • When one pointer is subtracted from another, the difference is the result of the expression: ((int)a - (int)b) / (int)sizeof(type pointed to) 5.1.4 • If the pointers point to objects whose alignment is the same as their size, this alignment ensures that division is exact. • If the pointers point to objects whose alignment is less than their size, such as packed types and most structs, both pointers must point to elements of the same array. Structures, unions, enumerations, and bitfields This section describes the implementation of the structured data types union, enum, and struct. It also discusses structure padding and bitfield implementation. See Anonymous classes, structures and unions on page 3-20 for more information. Unions When a member of a union is accessed using a member of a different type, the resulting value can be predicted from the representation of the original type. No error is given. Enumerations An object of type enum is implemented in the smallest integral type that contains the range of the enum. The storage type of an enum is the first of the following, according to the range of the enumerators in the enum: • unsigned char if not using --enum_is_int • signed char if not using --enum_is_int • unsigned short if not using --enum_is_int • signed short if not using --enum_is_int • signed int • unsigned int except C with --strict • signed long long except C with --strict • unsigned long long except C with --strict. Implementing enum in this way can reduce data size. The command-line option --enum_is_int forces the underlying type of enum to at least as wide as int. ARM DUI 0348A Copyright © 2007, 2010 ARM Limited. All rights reserved. Non-Confidential 5-7