11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

Descriptions of pragma directivesnameAn optional pushed or popped alignment labelDescriptionExample 1Use this pragma directive to specify the alignment of structs and union members.The #pragma pack directive affects declarations of structures following the pragmadirective to the next #pragma pack or end of file.Note that accessing an object that is not aligned at its correct alignment requires codethat is both larger and slower than the code needed to access the same kind of objectwhen aligned correctly. If there are many accesses to such fields in the program, it isusually better to construct the correct values in a struct that is not packed, and access thisinstead.Also, special care is needed when creating and using pointers to misaligned fields. Fordirect access to misaligned fields in a packed struct, the compiler will emit the correct(but slower and larger) code when needed. However, when a misaligned field is accessedthrough a pointer to the field, the normal (smaller and faster) code for accessing the typeof the field is used. In the general case, this will not work.This example declares a structure without using the #pragma pack directive:struct First{char alpha;short beta;};In this example, the structure First is not packed and has the following memory layout:alphabeta1 byte 1 byte 2 bytesNote that one pad byte has been added.Example 2This example declares a similar structure using the #pragma pack directive:#pragma pack(1)struct FirstPacked{char alpha;short beta;};#pragma pack()210<strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong>Reference Guide

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

Saved successfully!

Ooh no, something went wrong!