Operator declaration
Nick Treleaven
nick at geany.org
Fri Apr 24 14:52:46 UTC 2026
On Friday, 24 April 2026 at 09:49:31 UTC, Dom Disc wrote:
> On Thursday, 23 April 2026 at 15:25:35 UTC, H. S. Teoh wrote:
>
>> I hate D's policy on integer conversions.
>
> The funny fact is: during CTFE this promotion to int is NOT
> done.
>
> for(ubyte i = 0; i<256; ++i) ...
Can we make `i < 256` a compile-time error?
> This works, because i is promoted to int so it can an will
> reach 256.
>
> But during CTFE this is an infinite loop, because an ubyte is
> always <256
>
> One of the bugs that caught me on surprise.
It's an infinite loop at runtime. `i == 256` never happens, it
can't.
```d
void main()
{
import std.stdio;
for(ubyte i = 0; i<256; ++i)
i.writeln;
}
```
More information about the Digitalmars-d-learn
mailing list