Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stack overflow

Status
Not open for further replies.

Cagliostro

Programmer
Sep 13, 2000
4,226
GB
class x
{
public:
x(){x y;}//non allowed instanciating of x in ctor
};

when you will try to instanciate x, you will get stack overflow. Visual C++ don't say any errors or warnings. John Fill
1c.bmp


ivfmd@mail.md
 
Hmm... that is interesting. The compiler must create bad code, it could be a compiler bug worth telling microsoft. Is there a compiler option that dumps code after each pass?
 
Its probably a problem with the recursive properties of the call. It never completes an instantiation, the primary instantionation accesses the constructor which trys to make an instantiation, which accesses the constructor... etc

No wonder there is a stack overflow
 
the problem is not only in a ercursive all of a constructor. There also is a recursive instanciation and recursive allocation of memory :) John Fill
1c.bmp


ivfmd@mail.md
 
sorry, joe, two mistakes :)
recursive call of a constructor John Fill
1c.bmp


ivfmd@mail.md
 
Yes John you are right, the code compiles and links OK, but at runtime your stack will look like:

x::x() line 28 + 6 bytes
x::x() line 28 + 37 bytes
x::x() line 28 + 37 bytes
x::x() line 28 + 37 bytes
x::x() line 28 + 37 bytes
x::x() line 28 + 37 bytes

.....
wonder why first is only 6 bytes.

I think MS or any other vendor of C++ compiler will have problems because you could do:

class x
{
public:
x(){y first;};
};

class y
{
public:
y(){z second;};
};

class z
{
public:
z(){x third;};
};

place this classes in diferent files , make the includes and you will have probably another type of bad recursion. Excel - is one that verifies your recursion between spreadsheet's cells, I think it is much harder for VC compiler to predict that.
s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Also I can't stress this enough, you have to use capitals at the BEGINNING of a sentence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top