Topic: Need Borland C++ BI_IListImp help


Author: trickr@uh2372p03.daytonoh.ncr.com (Ralph Trickey)
Date: 14 Jan 94 14:29:08 GMT
Raw View
In article <19940113173624.vanvalke@rlvan.larc.nasa.gov> vanvalke@sealsun1.larc.nasa.gov (Randal L. VanValkenburg) writes:
>In Article <CJ4Dss.2B3@ennews.eas.asu.edu> "madden@enuxsa.eas.asu.edu (David
Madden)" says:>>
>> When I try to run the following code in IDE by single stepping (F8), the
>> code runs fine.  However, when I try to run the code, the output is as
>> expected, but the execution freezes.  The code is run on Borland C++, ver 3.1.
>>
>> I cannot figure what is wrong...
>>
>> ------------------------------  code  ------------------------------------
>>       BI_IListImp<int> questions; // note: necessary since I will be
>>                                       // adding my own structure as soon
>>                                       // as I get this working right!
>>
>>       int *x, *y, *z;
>>       *x = 3; *y = 4; *z = 5;
>>
>>       questions.add(x);
>>       questions.add(y);
>>       questions.add(z);
>Looks like you are dereferencing 3 uninitialized pointers (x, y, z) and
>then sticking the values 3, 4, 5 into these random memory locations. Why not
>try:
>       int x = 3;
>
>       questions.add(&x);

That's the right problem, but this answer will still leave pointers pointing
at local memory, which will be freed when the routine returns. You need to
allocate memory for x, y, an z to point at using the new operator.

Ralph




Author: vanvalke@sealsun1.larc.nasa.gov (Randal L. VanValkenburg)
Date: Thu, 13 Jan 1994 17:36 est
Raw View
In Article <CJ4Dss.2B3@ennews.eas.asu.edu> "madden@enuxsa.eas.asu.edu (David Madden)" says:
>
> When I try to run the following code in IDE by single stepping (F8), the
> code runs fine.  However, when I try to run the code, the output is as
> expected, but the execution freezes.  The code is run on Borland C++, ver 3.1.
>
> I cannot figure what is wrong...
>
> ------------------------------  code  ------------------------------------
>  BI_IListImp<int> questions; // note: necessary since I will be
>      // adding my own structure as soon
>      // as I get this working right!
>
>  int *x, *y, *z;
>  *x = 3; *y = 4; *z = 5;
>
>  questions.add(x);
>  questions.add(y);
>  questions.add(z);
Looks like you are dereferencing 3 uninitialized pointers (x, y, z) and
then sticking the values 3, 4, 5 into these random memory locations. Why not
try:
       int x = 3;

       questions.add(&x);
Randy VanValkenburg
NASA - Langley Research Cent




Author: madden@enuxsa.eas.asu.edu (David Madden)
Date: Tue, 4 Jan 1994 19:22:00 GMT
Raw View
When I try to run the following code in IDE by single stepping (F8), the
code runs fine.  However, when I try to run the code, the output is as
expected, but the execution freezes.  The code is run on Borland C++, ver 3.1.

I cannot figure what is wrong...

------------------------------  code  ------------------------------------

#include <iostream.h>
#include <iomanip.h>
#include <list.h>
#include <listimp.h>

main()
{
 BI_IListImp<int> questions; // note: necessary since I will be
     // adding my own structure as soon
     // as I get this working right!

 int *x, *y, *z;
 *x = 3; *y = 4; *z = 5;

 questions.add(x);
 questions.add(y);
 questions.add(z);


 BI_IListIteratorImp<int> newlst(questions);

 cout << "--------\n";

 while (newlst) {
  int *temp = newlst.current();
  cout << *temp << "\n";
  newlst++;
 }

return 0;
}

--------------------------  output -------------------------------------

--------
5
4
3

As mentioned, if single stepped via <F8>, the completed execution returns
to the IDE.  However, when trying to run the code, the output is generated
but the program "hangs" indefinitely, and does not return to the IDE.

Please help!

--


======================================================
|  David W. Madden   ||   Arizona State University   |
|  (602) 965-1792    ||   MADDEN@ENUXSA.EAS.ASU.EDU  |
======================================================