3 ms·
void in C can't be created, used, or passed around - () can.
by vertex-four 10y ago
void in C can't be created, used, or passed around - () can.
- shakna 10y agoBut void pointers can, and are often used.
- vertex-four 10y agoSo in Rust, the equivalent of void* with references instead looks like: enum Void{} fn foo(v: &Void){ ... } let bar : Void; fn abc() -> &Void{ ...} fn xyz() -> Void{ ... } You can't create a Void, and you can't cast to it either - it's not a bottom type. So you can't put anything in bar. And as a result, you can't create a reference to a Void, so you can't call foo. And abc and xyz just can't be implemented in the first place. On the other hand, you can do all of these just fine: fn foo(v: ()){ ... } fn bar(v: &()){ ... } ... let v = (); bar(&v); foo(v); The fact that you can create and use an empty tuple as a value shows that it is not equivalent to Void. (All statements here are made within the safe subset of the language - unsafe allows access to intrinsics that would allow a Void to be made, and a reference to Void.)
- kbp 10y agovoid * isn't related to void (or this discussion), they just reused the keyword.