This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Alignment Guarantees?
On 03/05/2012 09:49 AM, Jonathan Wakely wrote:
> On 5 March 2012 06:04, Jeffrey Walton wrote:
>> Does C/C++ or GCC offer any alignment guarantees?
>
> Alignment requirements are implementation-defined, usually imposed by
> the hardware.
Or the system ABI.
> C++ and GCC guarantee that data you declare or dynamically allocate
> will be correctly aligned, they don't guarantee that playing tricks
> with casts will produce correctly aligned data, whether that works
> depends on the hardware.
That's not quite right. As long as you follow the rules in the C
and C++ standards, everything will be correctly aligned. If you
do anything that is undefined according to the rules, all bets are
off.
Andrew.