# Why is assignment of a struct allowed and comparison not

**URL:** <https://ziggit.dev/t/why-is-assignment-of-a-struct-allowed-and-comparison-not/18309>\
**Category:** Explain\
**Created:** [November 11, 2026, 11:58am UTC](https://ziggit.dev/t/why-is-assignment-of-a-struct-allowed-and-comparison-not/18309 "2026-11-11T11:58:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [November 11, 2026, 11:58am UTC](https://ziggit.dev/t/why-is-assignment-of-a-struct-allowed-and-comparison-not/18309/1 "2026-11-11T11:58:34Z")

</div>

Well… the title of this topic is already self-explanatory.

Why can’t we (always) compare structs while assigning is always allowed?

```zig
const b: AnyStruct = .init(...);
const a: AnyStruct = b; // always allowed.
const eql: bool = (a == b); // not always allowed.

```

```zig
error: operator == not allowed for type

```

I know this is because the internal layout of a struct.  
But in my mind it goes like: “if Zig can copy it should also be able to compare”.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [November 11, 2026, 12:05pm UTC](https://ziggit.dev/t/why-is-assignment-of-a-struct-allowed-and-comparison-not/18309/2 "2026-11-11T12:05:43Z")

</div>

Because assignment does not imply that comparison is possible…

Structs are not special in this regard either, you can’t compare unions, or arrays, or slices, or tuples.

Why do you think assignment should imply comparison is possible? Is it because you are thinking about it as a bunch of bytes? Even that doesn’t support comparison on the language level, you have to compare the individual bytes…

Why would be being comprised of bytes imply comparison?

What about the meaning ascribed to those bytes, the actual type not the memory, why can’t that be incomparable even if it is assignable to memory?
