Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Itanium-based Systems: HP aC++/HP C Programmer's Guide > Chapter 2 Command-Line Options

Data Alignment and Storage

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

This section describes default data storage allocation and alignment for HP compiler data types.

Data storage refers to the size of data types, such as bool, short, int, float, and char*. Data alignment refers to the way the HP compiler aligns data structures in memory. Data type alignment and storage differences can cause problems when moving data between systems that have different alignment and storage schemes. These differences become apparent when a structure is exchanged between systems using files or inter-process communication. In addition, misaligned data addresses can cause bus errors when an attempt is made to dereference the address.

For information on unaligned data access, “Handling Unaligned Data”.

Table 2-2 “Size and Alignment of HP Compiler Data Types” lists the size and alignment of the HP compiler data types:

Table 2-2 Size and Alignment of HP Compiler Data Types

Data Type

Size (in bytes)

Alignment

bool

1

1-byte

char, unsigned char, signed char

1

1

wchar_t

4

4

short, unsigned short, signed short

2

2

int, unsigned int

4

4

long, unsigned long

4*

4*

float

4

4

__float80

16

16

__float128

16

16 in +DD64. 8 otherwise.

double

8

8

long double

16

8**

long long, unsigned long long

8

8

enum

4

4

arrays

Size of array element type

Alignment of array element type

struct

***

1-, 2-, 4-, 8-, or 16-byte

union

***

1-, 2-, 4-, 8-, or 16-byte

bit-fields

Size of declared type

Alignment of declared type

pointer

4*

4*

* In 64-bit mode, long, unsigned long, and pointer data types are 8 bytes long and 8-byte aligned.

** In 64-bit mode, long double is 16-byte aligned.

*** struct and union alignment are same and follow strict alignment of any member. Padding is done to a multiple of the alignment size.

 

-fshort-enums

cc -Agcc -Wc,--fshort-enums foo.c

aCC -Ag++ -Wc,--fshort-enums foo.c

The -fshort-enums option is used with the -Agcc or -Ag++ options to cause each enum type to be represented using the smallest integer type that is capable of representing all values of the enum type. Because it changes the representation of types, the code generated is not binary compatible with code compiled without the option. The primary use of this option is for compatibility with gcc, but it can provide performance improvement to applications that can accept the binary incompatibility.

-unum

+unum

The +unum option allows pointers to access non-natively aligned data. This option alters the way that the compiler accesses dereferenced data. Use of this option may reduce the efficiency of generated code. Specify num as 1, 2, or 4, as follows:

1 - Assume single byte alignment. Dereferences are performed with a series of single-byte loads and stores.

2 - Dereferences are performed with a series of two-byte loads and stores.

4 - Dereferences are performed with a series of four-byte loads and stores.

Example:

aCC +u1 app.C

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.