Segment violation (was Re: Why I could not cast string to int?)

xancorreu xancorreu at gmail.com
Thu Feb 2 08:28:53 PST 2012


I get "segment violation" error with  ./factorial 400000
How can I resolve it?

My code is:

import std.stdio, std.bigint, std.string, std.conv, std.stream;

BigInt recFactorial(int n) {
     if (n == 0)
         return BigInt(1);
     else
         return (BigInt(n) * recFactorial(n - 1));
}

void main(string[] args) {
     if (args.length != 2)
         writeln("Factorial requires a number");
     else
         try {
             writeln(recFactorial(std.conv.to!int(args[1])));
         } catch {
             writeln("Error");
         }
}



Thanks a lot,


More information about the Digitalmars-d-learn mailing list