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

Is it possible to export the returned value of const fn ? #252

Open
klefevre opened this issue Nov 22, 2018 · 1 comment
Open

Is it possible to export the returned value of const fn ? #252

klefevre opened this issue Nov 22, 2018 · 1 comment

Comments

@klefevre
Copy link

Hello,
Do you know if it's possible to export the returned value of a const fn e.g. mem::size_of ?

Here is an example:

#[repr(C)]
struct _PrivateStruct {
   a: i32,
   b: i32,
}

#[repr(C)]
pub const FOO: usize = std::mem::size_of::<_PrivateStruct>();

#[repr(C)]
pub struct PublicStruct {
    x: [i32; FOO],
}

Running cbindgen gives the following output where FOO isn't defined at all:

typedef struct {
    x: [i32; FOO], // FOO isn't define
} PublicStruct;

I tried some hacks like using macros, lazy_static, static variables but whether it doesn't compile or the value isn't exported.

Any thought on how to achieve this ? Any help would be very welcome :)

@eqrion
Copy link
Collaborator

eqrion commented Nov 26, 2018

Hmm, that's going to be tricky with cbindgen. cbindgen is just a parser of rust source code, so it doesn't have any information about compiler instrinsics like size_of. In addition, the value of size_of can vary by platform/architecture and cbindgen attempts to create a neutral header that can work on all platforms.

You might be interested in #214, which could give us a better chance at solving this.

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