3 ms·
Can anybody explain the downvotes? It looks suspicious. It's well known and long standing problem. Rust the Language allows proper enum, but Rust the Compiler
by v_lisivka 7y ago
Can anybody explain the downvotes? It looks suspicious.
It's well known and long standing problem. Rust the Language allows proper enum, but Rust the Compiler cannot pack enum into single value, as in C.
Example:
#[repr(C)]
#[repr(i32)]
#[derive(Debug)]
#[allow(dead_code)]
enum E {
A,
B,
C,
Unlabeled(i32),
}
fn main() {
{
let v: E = unsafe { std::mem::transmute::<(i32,i32), E>((0,0)) };
println!("v = {:?}", v)
}
{
let v: E = unsafe { std::mem::transmute::<(i32,i32), E>((1,1)) };
println!("v = {:?}", v)
}
{
let v: E = unsafe { std::mem::transmute::<(i32,i32), E>((2,2)) };
println!("v = {:?}", v)
}
{
let v: E = unsafe { std::mem::transmute::<(i32,i32), E>((3,3)) };
println!("v = {:?}", v)
}
{
let v: E = unsafe { std::mem::transmute::<(i32,i32), E>((3,55)) };
println!("v = {:?}", v)
}
{
let v: E = unsafe { std::mem::transmute::<(i32,i32), E>((55,55)) };
println!("v = {:?}", v)
}
}
Output:
v = A
v = B
v = C
v = Unlabeled(3)
v = Unlabeled(55)
v = A
- pleasecalllater 7y ago> Can anybody explain the downvotes? It looks suspicious. I can. This is a long tradition here. If someone criticizes something loved by people with little knowledge (aka fangirls and fanboys) then they downvote it. The truth doesn't matter, the hurt feelings do. And it's downvoted without any explanation. I had this many times, I'm thinking about not posting at all. It's not worth it. There is no discussion, just downvotes. I'm sure this will be downvoted too :)