Skip to content

Generation of const pointers #3347

@metaspace

Description

@metaspace

Given the following C heder:

const int* foo = ((int*) 3ULL);

bindgen will generate the following Rust code:

/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C" {
    pub static mut foo: *const ::std::os::raw::c_int;
}

The output I would expect (and need) to be generated is the following:

const FOO: *const c_int = 3usize as *const c_int;

Questions

  • Is there any way to configure bindgen to provide the output above?
  • Is the generation of current output a feature or a bug?
    • If it is a feature, what is the rationale behind it?

For context, we are hitting this in the Linux kernel when generating bindings for these kind of pointers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions