# Slice type coercion

**URL:** <https://ziggit.dev/t/slice-type-coercion/18168>\
**Category:** Explain\
**Tags:** zig-0-17\
**Created:** [November 1, 2026, 2:21am UTC](https://ziggit.dev/t/slice-type-coercion/18168 "2026-11-01T02:21:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeeqeeng](https://ziggit.dev/letter_avatar_proxy/v4/letter/z/8baadc/32.png) [@zeeqeeng](https://ziggit.dev/u/zeeqeeng)\
**Post date:** [November 1, 2026, 2:21am UTC](https://ziggit.dev/t/slice-type-coercion/18168/1 "2026-11-01T02:21:43Z")

</div>

I’m confused with the type coercion around the slice type. Here are examples:

1. coerce a slice to a many-item pointer. What’s the intention to give up the length property here? E.g.,

```zig
const tag_name = @tagName(TestEnum.TestEnumValue);
const ptr_tag_name: [*:0]const u8 = tag_name;

// test/behavior/string_literals.zig file in Zig codebase

```

1. comptime slice. Isn’t it **runtime-known** of the length for a slice? What’s actually a comptime slice?

```zig
test "comptime slice" {
    const test_string: []const u8 = "hello";
    try testing.expect(comptimeKnown(test_string));
}

// https://ziggit.dev/t/some-cool-language-tricks/18130#p-80662-h-1-figuring-out-if-a-value-is-comptime-1
pub inline fn comptimeKnown(val: anytype) bool {
    const Tuple = @TypeOf(.{val});
    return @typeInfo(Tuple).@"struct".field_attrs[0].@"comptime";
}
const std = @import("std");
const testing = std.testing;

```
