# Bit fields, like in C

**URL:** <https://forums.swift.org/t/bit-fields-like-in-c/34651>\
**Category:** Discussion\
**Created:** [March 20, 2020, 5:29am UTC](https://forums.swift.org/t/bit-fields-like-in-c/34651 "2020-03-20T05:29:28Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [March 20, 2020, 3:45pm UTC](https://forums.swift.org/t/bit-fields-like-in-c/34651/7 "2020-03-20T15:45:13Z")

</div>

If we ever have a "precise layout" feature, I think it should be directed squarely at use cases like network protocols and serialization. Language interoperation use cases should be handled by importing C headers. Storage optimization use cases should mostly be handled by (1) the compiler doing a certain amount of bit-packing of value types automatically, which will allow (2) programmers to rework their representations in order to take advantage of that.

That said, the compiler can't automatically compress to less than the formally-expressible range of a type. We can bit-pack `Bool` and frozen enums, but we'd still need some ability to just put a range constraint on an integer.

---

_[View the full topic](https://forums.swift.org/t/bit-fields-like-in-c/34651)._
