Zig's new bitCast semantics and LLVM back end improvements
Overall reception of the devlog and Zig
- Many readers praise the devlog’s depth and clarity, contrasting it with “low-effort” or AI-generated content elsewhere.
- Several say it makes them want to use Zig more and see these posts as effective “advertising” for the language.
- Some appreciate Zig’s stance on AI and its focus on careful, explicit design.
Arbitrary-width integers and packed structs
- Multiple commenters strongly like arbitrary-width ints for:
- Custom floats and ML formats.
- FPGA-style bit slicing and protocol/message parsing.
- Emulators: buses, odd-width registers/counters, and bit-accurate layouts matching datasheets.
- Guarding against errors (e.g., u6 shift counts, u12 sensor ranges) and compile-time range checking.
- Others prefer explicit packing/unpacking or bitsets (e.g., StaticBitSet) for performance or clarity, especially for very wide integers like u729.
- Zig’s model (logical bits, packed structs, and checked arithmetic) is highlighted as a major differentiator vs C bitfields.
New @bitCast semantics and endianness
- Old behavior: reinterpretation depended on machine endianness.
New behavior: operates on a logical, little-endian-style bit order that is the same on all targets. - Critics argue:
- This breaks the intuitive expectation that bit casting mirrors memory layout.
- Existing endian-aware code (using byte swaps) may now be wrong.
- A separate “logical bit” intrinsic plus a raw transmute would have been clearer.
- Defenders argue:
- It removes a major portability footgun and aligns with how packed structs already behave.
- Raw reinterpretation is still achievable via
@ptrCast+ dereference / memcpy. - Pre-1.0 breaking changes are acceptable, and this likely fixes some previously non-portable code.
Debate over u24 and ABI / hardware details
- One side views allowing
[3]u8↔u24bitcasts as conceptually wrong unlessu24is truly 24 bits in layout. - Others respond:
- Zig defines a clear ABI where a
u24can be backed by a larger integer but still represent a 24-bit range. - Arbitrary-width types resemble C23
_BitIntand can map well even to niche hardware (e.g., 24-bit multiply via FP units, specialized GPU ops). - They enable tight packing and safer domain modeling even when not byte-aligned.
- Zig defines a clear ABI where a
Endianness in real protocols and formats
- One commenter claims “everyone agrees on little-endian” and that conversions are rarely needed; others push back:
- Big-endian file formats (TIFF, PSD, AIFF) and standardized “network byte order” still exist.
- Low-level networking, kernels, and drivers must care about endianness and frequently convert at boundaries.
- Some recommend a clear separation between wire types and in-memory domain types, with conversion at the boundary.
Language ecosystem, marketing, and “social issues”
- There’s curiosity about why Zig gets far more attention than other “C replacements” like Odin or C3.
- Explanations offered:
- Strong C interop, including importing C headers directly.
- High-visibility projects using Zig (e.g., tools and databases mentioned).
- Clear vision, conferences, and deliberate community-building/marketing.
- One commenter attributes part of Zig’s visibility to perceived alignment with certain “social issues”; others explicitly reject this as a major factor and say they use Zig regardless of the creator’s politics.
Broader meta-discussion
- Some contrast meticulous low-level Zig work (struct packing, bit layouts) with “YOLO” high-level app development, including LLM-heavy workflows.
- There are brief tangents on:
- The future role of LLMs in software development vs “craft” programming.
- Use and input methods for em-dashes and Unicode punctuation.
- A playful question about using
@bitCastfor base64-like transforms; the answer notes it would technically work but likely generate poor code for large buffers.