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

How to check that Rust type size is equal to C++ type size. #1373

Open
noy1993 opened this issue Aug 31, 2024 · 0 comments
Open

How to check that Rust type size is equal to C++ type size. #1373

noy1993 opened this issue Aug 31, 2024 · 0 comments

Comments

@noy1993
Copy link

noy1993 commented Aug 31, 2024

I have a question: If the size of types in C++ and Rust are different, the code might still compile, but it would be very unsafe. Is there a way to make the compiler throw an error when the sizes of C++ and Rust types do not match?

For example, with the following code, a Rust Foo struct could be directly transmuted into a C++ Foo.

rust code:

struct Foo{
    v:f64
    v2:f64
}

unsafe impl ExternType for Foo {
    type Id = cxx::type_id!("Foo");
    type Kind = cxx::kind::Trivial;
}

c++ code:

class Foo{
public:
    double v;
};
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

1 participant