Sun Studio 12: C++ User's Guide

A.2.147 -xmemalign=ab

(SPARC) Use the -xmemalign option to control the assumptions the compiler makes about the alignment of data. By controlling the code generated for potentially misaligned memory accesses and by controlling program behavior in the event of a misaligned access, you can more easily port your code to SPARC.

Specify the maximum assumed memory alignment and behavior of misaligned data accesses. There must be a value for both a (alignment) and b (behavior). a specifies the maximum assumed memory alignment and b specifies the behavior for misaligned memory accesses.

For memory accesses where the alignment is determinable at compile time, the compiler generates the appropriate load/store instruction sequence for that alignment of data.

For memory accesses where the alignment cannot be determined at compile time, the compiler must assume an alignment to generate the needed load/store sequence.

If actual data alignment at runtime is less than the specified alignment, the misaligned access attempt (a memory read or write) generates a trap. The two possible responses to the trap are

A.2.147.1 Values

The following table lists the alignment and behavior values for -xmemalign

Table A–39 The -xmemalign Alignment and Behavior Values





Assume at most 1 byte alignment. 

Interpret access and continue execution. 

Assume at most 2 byte alignment. 

Raise signal SIGBUS. 

Assume at most 4 byte alignment. 

For variants of -xarch=v9 only:

Raise signal SIGBUS for alignments less or equal to 4,otherwise interpret access and continue execution. For all other -xarch values, the f flag is equivalent to i.

Assume at most 8 byte alignment. 



Assume at most 16 byte alignment 


You must specify -xmemalign whenever you want to link to an object file that was compiled with the value of b set to either i or f. For a complete list of all compiler options that must be specified at both compile time and at link time, see 3.3.3 Compile-Time and Link-Time Options.


The following default values only apply when no -xmemalign option is present:

Here is the default when the -xmemalign option is present but no value is given:


The following table shows how you can use -xmemalign to handle different alignment situations.

Table A–40 Examples of -xmemalign




There are many misaligned accesses so trap handling is too slow. 


There are occasional, intentional, misaligned accesses in code that is otherwise correct. 


There should be no misaligned accesses in the program. 


You want to check for possible odd-byte accesses. 


You want to check for possible odd-byte access and you want the program to work.