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

Add support for std::mem::offset_of #984

Open
basile-henry opened this issue Jul 12, 2024 · 1 comment
Open

Add support for std::mem::offset_of #984

basile-henry opened this issue Jul 12, 2024 · 1 comment

Comments

@basile-henry
Copy link

It looks like std::mem::offset_of isn't supported yet

src/lib.rs:

struct A {
    a: bool,
}

pub const offset: usize = std::mem::offset_of!(A, a);
$ cbindgen --config template.toml --crate repro --output my_header.h
WARN: Skip repro::offset - (Unsupported expression. Macro(ExprMacro { attrs: [], mac: Macro { path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(std), arguments: None }, Colon2, PathSegment { ident: Ident(mem), arguments: None }, Colon2, PathSegment { ident: Ident(offset_of), arguments: None }] }, bang_token: Bang, delimiter: Paren(Paren), tokens: TokenStream [Ident { sym: A }, Punct { char: ',', spacing: Alone }, Ident { sym: a }] } }))
@emilio
Copy link
Collaborator

emilio commented Aug 10, 2024

This seems generally hard because we don't have compiler information. We could try to translate it to an offsetof in C / C++ perhaps tho?

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

No branches or pull requests

2 participants