3 ms·
> It is strange to pick on C for this, as I cannot think of a single language that works the way the author seems to want. Agreed, though recent crop of langua
by masklinn 10y ago
> It is strange to pick on C for this, as I cannot think of a single language that works the way the author seems to want.
Agreed, though recent crop of languages with less implicit conversion will reject the entire thing rather than silently expand the value at the end, e.g. in Rust
error[E0308]: mismatched types
--> <anon>:7:19
|
7 | tableOffset = (l1Index * L1_TABLE_GRANULARITY) +
| ^ expected u64, found u32
error: aborting due to previous error
- zzzcpan 10y agoSo far I found this mandatory explicit conversion to only get in the way. Caused me a bug even (in Go), because it made it too noisy and very unclear where the value was unnecessarily trimmed.
- masklinn 10y agoYeah it's a mixed blessing, implicit conversions are sources of bugs but the lack of them can be a real pain in the ass when mixing numerics of different bit width. Maybe it's possible to write a rustc plugin to opt-in auto-expansion of numeric types in the style of unsafe blocks? E.g. `extend!(numexpr)` which would go through the numeric expression and automatically (sign-|zero-)extend values to make it typecheck?