May 14, 2010
I have the following program on Mac OS X 10.6.3 running dmd version 2.043:

$ cat if.d
import std.stdio;

void main (string [] args)
{
  foreach(arg; args)
    writeln(arg);

  auto vec = new double[10];

  foreach(i, ref x; vec) { x = cast(double) i; }

  if (args.length > 1 && args[1] == "bar") { vec[] *= 0.5; }
}

This program compiles with no warnings. However, when I run it, I get a bus error regardless of the value of the first command-line argument, or whether it's present at all. I also get bus error if I eliminate the conditional altogether. AFAICT, the array operation I'm doing on vec is legitimate according to

http://www.digitalmars.com/d/2.0/arrays.html

and the fact that the program bombs out regardless of the outcome of the test in the conditional is particularly mystifying.

Any help would be greatly appreciated.

Thanks,
Pillsy
May 14, 2010
On 15/05/10 00:14, Pillsy wrote:
> I have the following program on Mac OS X 10.6.3 running dmd version 2.043:
>
> $ cat if.d
> import std.stdio;
>
> void main (string [] args)
> {
>    foreach(arg; args)
>      writeln(arg);
>
>    auto vec = new double[10];
>
>    foreach(i, ref x; vec) { x = cast(double) i; }
>
>    if (args.length>  1&&  args[1] == "bar") { vec[] *= 0.5; }
> }
>
> This program compiles with no warnings. However, when I run it, I get a bus error regardless of the
> value of the first command-line argument, or whether it's present at all. I also get bus error if I
> eliminate the conditional altogether. AFAICT, the array operation I'm doing on vec is legitimate
> according to
>
> http://www.digitalmars.com/d/2.0/arrays.html
>
> and the fact that the program bombs out regardless of the outcome of the test in the conditional is
> particularly mystifying.
>
> Any help would be greatly appreciated.
>
> Thanks,
> Pillsy

I'm using dmd 2.045 on linux here, and that example works fine, so I'd guess it's an OS X specific bug if you can't get it working with newer versions of dmd... There were some issues to do with array operations that have been fixed recently, so I'd try a newer dmd. If that doesn't fix it report a bug.