You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To me it looks like that the non 16 bit aligned packed sub-struct is causing a problem here.
Writes to the interpreted pointer do not end up in the right locations in memory.
From the documentation this appeared to me the right way to do an interpret cast, or am I missing something here?
Moving all the fields of Cat (including the culprit byte) into Foo makes it behave it again as I would expect.
const std = @import("std");
const Cat = packed struct {
culprit: u8, // comment in this field and buff will look as expected
f1: u16,
f2: u16,
};
const Foo = packed struct {
cat1: Cat,
};
pub fn main () !void {
var buff = [_]u8{0} ** (@sizeOf(Foo));
var foo = @ptrCast(*Foo, &buff);
foo.cat1.f1 = 0x11;
foo.cat1.f2 = 0x22;
var w = std.io.getStdOut().writer();
// with culprit byte I get 2200000000000000
// with *no* culprit byte I get, as expected, 11002200
try w.print("{x}\n", .{buff});
}
The text was updated successfully, but these errors were encountered:
Observed with latest release 0.6.0+66d76cc4f.
Please see my example below
To me it looks like that the non 16 bit aligned packed sub-struct is causing a problem here.
Writes to the interpreted pointer do not end up in the right locations in memory.
From the documentation this appeared to me the right way to do an interpret cast, or am I missing something here?
Moving all the fields of
Cat
(including the culprit byte) into Foo makes it behave it again as I would expect.The text was updated successfully, but these errors were encountered: