# panic: runtime error: unaligned memory access

- **ID:** `go/cgo-struct-alignment`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Passing a Go struct with different alignment requirements to C, causing unaligned access on some architectures (e.g., ARM).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.19 | active | — | — |
| 1.20 | active | — | — |

## Workarounds

1. **Ensure Go struct has same alignment as C using `unsafe.Alignof`** (80% success)
   ```
   type MyStruct struct {
    A int32
    B int64
}
_ = unsafe.Alignof(MyStruct{}) // check alignment
   ```
2. **Use `C.struct_MyStruct` directly in Go** (90% success)
   ```
   // #include <mylib.h>
// type GoStruct C.struct_MyStruct
   ```

## Dead Ends

- **Adding `// #pragma pack(1)` in C code** — Go struct may still be aligned differently. (50% fail)
- **Ignoring the panic and hoping for the best** — Will crash on strict alignment platforms. (100% fail)
