Skip to content

Add Box<T> to the supported types, where T: Sized #474

Closed

Description

@eliaslevy

As of Rust 1.41.0:

Box<T>, where T: Sized is now ABI compatible with the C language's pointer (T*)
types. So if you have an extern "C" Rust function, called from C, your Rust function can
now use Box<T>, for some specific T, while using T* in C for the corresponding function.

(from Announcing Rust 1.41.0)

So that

#[no_mangle]
pub extern fn test() -> Box<i32> { Box::new(1i32) }

should generate

int32_t * test();

Activity

  1. emilio commented on Feb 21, 2020

    @emilio
    Collaborator

    This makes sense. To be clear, you can already do this in C++ if you do:

    template <typename T> using Box = T*;
    

    For C, and maybe for function arguments, we probably want to do this automagically.

    The reason why I think we shouldn't do it automatically for C++ members and such is that in C++ having Box<T> is actually useful (if you don't care about Box parameter-passing).

    See also the discussion in #451

  2. mgeier commented on Mar 27, 2020

    @mgeier

    For C, and maybe for function arguments, we probably want to do this automagically.

    Are there any news on this?

    It would be great to have this!

  3. emilio commented on Oct 7, 2020

    @emilio
    Collaborator

    4ce324c fixed this.

  4. mgeier commented on Oct 7, 2020

    @mgeier

    Thanks @emilio, this works great!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions