Is this reasonable?

Ary Borenszweig ary at esperanto.org.ar
Thu Dec 5 10:47:27 PST 2013


On 12/5/13 2:15 PM, Steve Teale wrote:
> Here I feel like a beginner, but it seems very unfriendly:
>
> import std.stdio;
>
> struct ABC
> {
>     double a;
>     int b;
>     bool c;
> }
>
> ABC[20] aabc;
>
> void foo(int n)
> {
>     writefln("n: %d, aabc.length: %d", n, aabc.length);
>     if (n < aabc.length)
>        writeln("A");
>     else
>        writeln("B");
> }
>
> void main(string[] args)
> {
>     int n = -1;
>     foo(n);
> }
>
> This comes back with "B".
>
> If I change the test to (n < cast(int) aabc.length), then all is well.
>
> Is this unavoidable, or could the compiler safely make the conversion
> implicitly?

Cough, cough, make array length be an int.

Do you really need arrays that big? :-S

(I'm talking to Mr. D Compiler here)


More information about the Digitalmars-d-learn mailing list