How to do align cast in rust?

give an example.

just for learning purpose

Please clarify what you mean by "align cast".

struct ok {
f: u8
}

struct not{
f: u16
}

fn main (){

 let mut z = ok{ f:4};

// z alignment is 1 byte..
// now what I want is represent z adress to other type with different alignment

let mut x :*not= &z;

That is not guaranteed.

That is instant UB. What are you programming that you need that? Are you translating C code?

If you give us the bigger picture, we may better help you finding idiomatic alternatives.

1 Like

(Also please read the pinned post on code formatting.)

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.