How to enlarge the stack size?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have a simple recursive function:

-----------------------------------------------------------------------------------------------------------------------

bool sestavi(long s,long *seznam,long *seznamA,long k,long *n){ 
    
    if(seznam[k] == s){
        seznamA[seznamA[*n-1]++]=seznam[k];
        return true;
    }
    
    if(k == 0)    return false;    

    if(seznam[k] > s){
        if(sestavi(s,seznam,seznamA,k-1,n))    
            return true;
        else
            return false;
    }
        
    if(sestavi(s-seznam[k],seznam,seznamA,k-1,n)){
        seznamA[seznamA[*n-1]++]=seznam[k];
        return true;
    }
    else{
        if(sestavi(s,seznam,seznamA,k-1,n))
            return true;
        else
            return false;            
    }    
}

----------------------------------------------------------------------------------------------------------------------- 

 which produces the Segmentation fault run time error, at some critical
recursion depth. 
I guess, I have the stack overflow problem. Parameter seznamA[*n-1] is
surely well bounded and this is not a problem.

I thought, enlarging the stack size would solve the problem? But how
should I do this? Is there another, more elegant solution?
Please help !

Thanks in advance,

Benjamin




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux