Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packed struct - strange field offset #2713

Closed
markfirmware opened this issue Jun 20, 2019 · 2 comments
Closed

packed struct - strange field offset #2713

markfirmware opened this issue Jun 20, 2019 · 2 comments

Comments

@markfirmware
Copy link
Contributor

markfirmware commented Jun 20, 2019

This program displays 4 for the offset of b, where I am expecting it to be 16.

Linux localhost 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1 (2019-04-12) x86_64 GNU/Linux
0.4.0+381c6a38

const std = @import("std");

const S = packed struct {
    a: u32,
    pad: [3]u32,
    b: u32
};

pub fn main() anyerror!void {
    var offset: usize = @byteOffsetOf(S, "b");
    std.debug.warn("offset {}\n", offset);
}
@FireFox317
Copy link
Contributor

Related: #2627

@SamTebbs33
Copy link
Contributor

Yeah this is a duplicate of the issue linked by @timonkruiper I found a little while ago, where the total size of the struct is also wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants