Handling unsafe result outside unsafe block

I've the below simple code that is working perfectly:

extern { fn triple(x: i32) -> i32; }

fn main() {
    let num = 2;
    unsafe { let num_tri = triple(num); println!("\nTriple of {} is: {}", num, num_tri); };
}

Can I re-write it something like:

fn main() {
    let num = 2;
    let num_tri: i32 = unsafe { triple(num); };
    println!("\nTriple of {} is: {}", num, num_tri); 
}

I tried the above but got an error:

image

remove the semicolon after triple inside the unsafe block

1 Like

Thanks for the quick correct simple answer :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.