DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Really Weird Error... Fibonacci Nums (http://www.daniweb.com/forums/thread14768.html)

lostinthespiral Nov 29th, 2004 12:41 am
Really Weird Error... Fibonacci Nums
 
I'm having some real problems with a code that is supposed to find Fibonacci numbers using recursive, iterative, and optimized recursive techniques. I keep on getting this really strange error though: "fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) Please choose the technical Support command on the Visual C++ Help menu, or open the technical Support help file for more information Error executing cl.exe.". If anyone could think of some advice, it would be really helpful. Thanks!

#include <iostream>
#include <ctime>

using namespace std;

typedef int* IntPtr;

long iter(int n)
{
    int a = 1, b = 1;
    for (int i = 2; i <= n; i++)
    {
        int c = a + b;
        a = b;
        b = c;
    }         
    return b;
}

int optRecur(int n, int array[])
{
        if (array[n] != 0)
                return array[n];
        if ((n == 0) || (n == 1))
                array[n] = 1;
        else
                array[n] = optRecur(n-1,array) + optRecur(n-2,array);
        return array[n];
}

void optRecurHelp(int n)
{
        int* a = NULL;
        a = new int[n];
        for(int i = 0; i <= n; ++i)
                a[i] = 0;
        optRecur(n,a);
        delete [] a;
        a = NULL;
}

long recur(int n)
{
    if ( n == 0 || n == 1 )
                return 1;
    else
        return recur(n - 1) + recur(n - 2);
}

long time(int n, int funct)
{
        double emptyLoop;
        double j;

        if(funct == 1)
        {
                clock_t start,end;
                start = clock();
                for (int i=0;i<100000000;i++)
                        recur(n);
                end = clock();
                emptyLoop = end-start;
                double time_passed = static_cast<double>(end-start)/CLOCKS_PER_SEC;
                j = (((end-start)-emptyLoop)/100000000);
        }
        if(funct == 2)
        {
                clock_t start,end;
                start = clock();
                for (int i=0;i<100000000;i++)
                        iter(n);
                end = clock();
                emptyLoop = end-start;
                double time_passed = static_cast<double>(end-start)/CLOCKS_PER_SEC;
                j = (((end-start)-emptyLoop)/100000000);
        }
        if(funct == 3)
        {
                clock_t start,end;
                start = clock();
                for (int i=0;i<100000000;i++)
                        optRecurHelp(n);
                end = clock();
                emptyLoop = end-start;
                double time_passed = static_cast<double>(end-start)/CLOCKS_PER_SEC;
                j = (((end-start)-emptyLoop)/100000000);
        }
        return j;
}

int main()
{
        int num1;
        int num2;

        cout << "What number would you like to compute? " << endl;
        cin >> num1;
        cout << "What function (recursive=1, iterative=2, optimized recursive=3)? " << endl;
        cin >> num2;
        cout << time(num1,num2) << endl;
        return 0;
}

big146 Nov 29th, 2004 1:06 am
Re: Really Weird Error... Fibonacci Nums
 
Try removing optimazation options 0g/ 0i/ 0a. Remove one at a time to see wich one might be the culprit.

lostinthespiral Nov 29th, 2004 4:16 am
Re: Really Weird Error... Fibonacci Nums
 
Tried. Fixed. Still get the same error.


All times are GMT -4. The time now is 9:38 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC