Void is surprisingly useful.
Void is surprisingly useful.
Posted Sep 9, 2026 11:47 UTC (Wed) by ralfj (subscriber, #172874)In reply to: Void is surprisingly useful. by dcoutts
Parent article: Stabilizing Rust's never type
Note that Haskell's Void and C's void are very different types. If we map them both to Rust, Haskell's Void is like ! (the empty type) and C's void is like () (the unit type). The fact that C's void is often described as a "type with no values" is extremely misleading and confusing: C's void has exactly one value, and because there is only one value you don't have to spell it out and it encodes 0 bits of information. In Rust if a function has return type () you also don't need to spell out its return value, but you can if you want -- the syntax for the only value of the unit type is () as well.
"void" sounds like it should be an empty type, so IMO it is very unfortunate that C picked this term.
