Search code examples
cprocessorturbo-c

Resumable processor fault


The code below is ok with return n <= 100 && (printf("%d\n", n), print(n+1)) || 0; but gives error for return n <= 1000 && (printf("%d\n", n), print(n+1)) || 0;

#include <stdio.h>

int print(int n)
{
   return n <= 1000 && (printf("%d\n", n), print(n+1)) || 0;
}

int main(void)
{
   print(1);
   return 0;
}

This code has following error : Divide error expectation and Resumable processor fault

I'm using Borland Turbo c++ 4.5 on windows 7.

How to fix it and also suggest a good C(specifically) IDE. I think eclipse c/c++ is a good option but confused.


Solution

  • Looks like a simple stack overflow caused by the recursion depth. Your options:

    1. Don't worry about it, you'd never write this sort of code for real.
    2. Increase the stack size.
    3. Do your homework assignment without using recursion if that is permitted.