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

Create successful ePaper yourself

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

<strong>Compiler</strong>-specific Features<br />

• The effect of casting away __packed is undefined. The effect of casting a non<br />

packed structure to a packed structure is undefined. A pointer to an integral type<br />

can be legally cast, explicitly or implicitly, to a pointer to a packed integral type.<br />

You can also cast away the __packed on char types.<br />

• There are no packed array types. A packed array is an array of objects of packed<br />

type. There is no padding in the array.<br />

Example<br />

Example 4-4 shows that a pointer can point to a packed type.<br />

Example 4-4 Pointer to packed<br />

typedef __packed int* PpI; /* pointer to a __packed int */<br />

__packed int *p; /* pointer to a __packed int */<br />

PpI p2; /* 'p2' has the same type as 'p' */<br />

/* __packed is a qualifier */<br />

/* just like 'const' or 'volatile' */<br />

typedef int *PI; /* pointer to int */<br />

__packed PI p3; /* a __packed pointer to a normal int */<br />

/* -- not the same type as 'p' and 'p2' */<br />

int *__packed p4; /* 'p4' has the same type as 'p3' */<br />

Example 4-5 shows that when a packed object is accessed using a pointer, the compiler<br />

generates code that works and that is independent of the pointer alignment.<br />

Example 4-5 Packed structure<br />

typedef __packed struct<br />

{<br />

char x;<br />

// all fields inherit the __packed qualifier<br />

int y;<br />

} X; // 5 byte structure, natural alignment = 1<br />

int f(X *p)<br />

{<br />

return p->y;<br />

}<br />

// does an unaligned read<br />

typedef struct<br />

{<br />

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

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!