# Prevent Zig from reordering instructions

**URL:** <https://ziggit.dev/t/prevent-zig-from-reordering-instructions/15814>\
**Category:** Help\
**Tags:** language, compiler\
**Created:** [May 31, 2026, 4:09am UTC](https://ziggit.dev/t/prevent-zig-from-reordering-instructions/15814 "2026-05-31T04:09:47Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [May 31, 2026, 5:23am UTC](https://ziggit.dev/t/prevent-zig-from-reordering-instructions/15814/4 "2026-05-31T05:23:44Z")

</div>

A way to force the compiler to correctly order the instructions is to use [`std.mem.doNotOptimizeAway`](https://ziglang.org/documentation/master/std/#std.mem.doNotOptimizeAway) but you must be sure that the CPU does not reorder them.  
See: [How to use std.mem.doNotOptimizeAway?](https://ziggit.dev/t/how-to-use-std-mem-donotoptimizeaway/4677)

---

_[View the full topic](https://ziggit.dev/t/prevent-zig-from-reordering-instructions/15814)._
