Comptime eval error calling @intFromPtr

This works fine at runtime but at comptime it’s a no-go.

ub fn main() !void {
    comptime {
        const s = "Hello";
        _ = @intFromPtr(s.ptr);
    }
}

I get

src/main.zig:6:13: error: unable to evaluate comptime expression
        _ = @intFromPtr(s.ptr);
            ^~~~~~~~~~~~~~~~~~
src/main.zig:6:26: note: operation is runtime due to this operand
        _ = @intFromPtr(s.ptr);
                        ~^~~~

It’s not the field access. @intFromPtr is runtime only, and so is @ptrFromInt. Pointers at comptime are more limited than during runtime.

Ok, that certainly clears things up. I was trying to calculate the offset of a slice item given its pointer and the source slice, which works at runtime. I guessed it would work at comptime given a comptime context guaranteeing a comptime string, but no luck. Thanks for the info!