#@ptrCast between slices changing the length

1 messages · Page 1 of 1 (latest)

fresh acorn
#

This seems to be on its way: https://github.com/ziglang/zig/issues/20057
How would I do this in the meantime?
I am trying to return an array with random content of a given numeric type.
This is a "section of my function.

// `T` and `size` are inputs
const bytes = @sizeOf(T) * size;
const arr = try allocator.alloc(u8, bytes);
try std.posix.getrandom(arr);
return @ptrCast(arr); // return type is []u16
GitHub

Zig Version 0.12.0 Steps to Reproduce and Observed Behavior const std = @import("std"); const builtin = @import("builtin"); test { const a: u32 = 0xCE94C13E; const b: *const u32...

high wasp
#

std.mem.bytesAsSlice