Rust and C++ Compatibility

I have a C++ code where I created a pointer to pointer in such manner:

int **arr;
arr = new int *[10];
for(int i =0;i<10;i++)
     arr[i] = new int [10];

pass_to_func() is a function inside rust (I have made it available to C++ through shared library).

pass_to_func defined inside Rust:

 pub unsafe extern "C" fn pass_to_func(arr: *mut *mut i32)
         //access arr

My query is how we can access and modify the values of arr inside Rust. A code snippet would be really helpful.

Please use proper code formatting. Instructions are here:

You can add one to every value like this:

pub unsafe extern "C" fn pass_to_func(arr: *mut *mut i32) {
    for i in 0..10 {
        for j in 0..10 {
            *(*arr.add(i)).add(j) += 1;
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.