On Sat, May 17, 2025 at 07:09:40AM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Given that Java and C# disallow narrowing conversions, I expect that > they have similar restrictions, but I haven't done much with either of > them any time recently, so I'm not sure what they do with smaller > integer types and arithmetic. [...] > It's just that the fact that smaller integer types get converted to > int for arithmetic makes it worse, though if they weren't, you'd be > getting integer overflow with them pretty frequently, I expect. [...]
This is why my proposed nopromote package uses the wrapper function .np to overtly mark an expression as being computed in narrow width, therefore there's the risk of wraparound issues. ``` import nopromote; byte b = 120; b = b.np + 5; // .np overtly marks this as narrow int arithmetic b = b.np * 2; // you're on your own here when this overflows // Though you should't be using narrow ints if you didn't know how to // deal with it properly in the first place. ``` T -- The most powerful one-line C program: #include "/dev/tty" -- IOCCC