Top "Memory-alignment" questions

Memory alignment means that objects and variables reside at particular offsets in the system's memory.

Compiler Warning when using Pointers to Packed Structure Members

Many C/C++ compilers (including gcc and clang) have a feature called packed structures. It comes in handy for a …

c++ c pointers struct memory-alignment
What's the actual effect of successful unaligned accesses on x86?

I always hear that unaligned accesses are bad because they will either cause runtime errors and crash the program or …

performance memory x86 alignment memory-alignment
Take advantage of ARM unaligned memory access while writing clean C code

It used to be that ARM processors were unable to properly handle unaligned memory access (ARMv5 and below). Something like …

c arm memory-alignment
Why does -Wcast-align not warn about cast from char* to int* on x86?

I understand that gcc has an option -Wcast-align which warns whenever a pointer is cast such that the required alignment …

c memory-alignment gcc-warning typecasting-operator
Struct Reordering by compiler

Suppose I have a struct like this: struct MyStruct { uint8_t var0; uint32_t var1; uint8_t var2; uint8_t …

c++ c struct memory-alignment
Why is integer assignment on a naturally aligned variable atomic on x86?

I've been reading this article about atomic operations, and it mentions 32bit integer assignment being atomic on x86, as long …

c++ concurrency x86 atomic memory-alignment
Does unaligned memory access always cause bus errors?

According to the Wikipedia page Segmentation fault, a bus error can be caused by unaligned memory access. The article gives …

c memory-alignment
Why does struct alignment depend on whether a field type is primitive or user-defined?

In Noda Time v2, we're moving to nanosecond resolution. That means we can no longer use an 8-byte integer to …

c# .net struct clr memory-alignment
Why does the Mac ABI require 16-byte stack alignment for x86-32?

I can understand this requirement for the old PPC RISC systems and even for x86-64, but for the old …

macos memory-alignment callstack calling-convention abi