tag:blogger.com,1999:blog-1016709139053396535.post4683717563286767171..comments2024-03-18T17:34:35.079+00:00Comments on A Smackerel of Opinion: A Common C Integer Multiplication MistakeColin Ian Kinghttp://www.blogger.com/profile/06458723239721015750noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-1016709139053396535.post-51626135067980241072021-03-31T11:55:57.848+01:002021-03-31T11:55:57.848+01:00I'll just say it: If there's an arithmetic...I'll just say it: If there's an arithmetic operation on the right side of an assignment, compiler should warn (and error with -Werror) if the result is a smaller type than the target type.<br /><br />This gets you closer to rust semantics<br /><br />error[E0308]: mismatched types<br /> --> src/main.rs:4:19<br /> |<br />4 | let c : u64 = a * b;<br /> | --- ^^^^^<br /> | | |<br /> | | expected `u64`, found `u8`<br /> | | help: you can convert a `u8` to a `u64`: `(a * b).into()`<br /> | expected due to this<br /><br />and makes stuff safejakhttps://www.blogger.com/profile/17642321912779274665noreply@blogger.com