Compile Time Recursion Warning

Posted on 2007-10-05
Last Modified: 2013-12-14
I've got a visual c++ application that i ported to .NET.  I have only fixed the compile time errors.  However, I get one compile warning for a line within one of my functions:

"recursive on all control paths, function will cause runtime stack overflow"

void C2DMyArray::SetSize(int newX, int newY, int nGrowBy)
      SetSize( newX*newY, nGrowBy);
      m_nSizeX = newX;
      m_nSizeY = newY;

where C2DMyArray is derived from CTypedPtrArray.

Any thoughts on how to avoid this recursion?

Thanks ahead of time.
Question by:clintonJ
    LVL 43

    Expert Comment

    void C2DMyArray::SetSize(int newX, int newY, int nGrowBy)
      //    SetSize( newX*newY, nGrowBy);   <--- Don't call it here, stop the recursion
          m_nSizeX = newX;
          m_nSizeY = newY;

    Why would you want to call the function from inside itself?  Seems like you have an error in your logic.
    LVL 22

    Accepted Solution

    It looks like you intend to call some overloaded SetSize that takes two arguments instead of three.

    The compiler is thinking you want the function to call itself, which makes no sense, and the number of arguments is wrong.

    How about you rename the 2-parameter function to something like "SetSize2", or rename the outer one to "SetSize3"?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now