Thread: Re: [Dev-C++] Buggy standard library?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Scott S. <age...@co...> - 2004-04-12 23:32:09
|
Try manually calling the destructor in your code. I am not a master of
C++, but I think I see what is going on here. The "World" class is
global. Therefore, its life is the entire program. However, when main
ends, the program ends. The solution here would probably to create an
instance of the class within main or call the destructor yourself in the
code, but I think the latter is poor programming, does anybody else know?
Latif Dokter wrote:
> here is the full code
> #include <iostream>
> #include <stdlib.h>
>
> using namespace std;
> class World
> {
> public:
> World () { std::cout << "Hello!\n"; }
> ~World () { std::cout << "Goodbye!\n"; }
> };
>
> World TheWorld;
>
> int main(int argc, char *argv[])
> {
>
> system("PAUSE");
> return 0;
> }
>
> /-------Original Message-------/
>
> /*From:*/ Scott Simontis <mailto:age...@co...>
> /*Date:*/ 04/12/04 10:55:55
> /*To:*/ Latif Dokter <mailto:ld...@op...>
> /*Subject:*/ Re: [Dev-C++] Buggy standard library?
>
> Did you call the destructor?
> Latif Dokter wrote:
>
> > I am using Dev.C++ 4.9.8.7 When creating a program with class World
> > where World () {} says Hello and ~World() {} says goodbye World
> > TheWorld; when compiled and executed
> > in Ms dos console the program prints hello but doesn't print goodbye I
> > have read that I may have a buggy version of the standard library if
> > so is there a patch if not what is happening and how can I fix it
> >
> >
> >
> >
> > ____________________________________________________
> > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9
> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>> /IncrediMail/
> > - *Email has finally evolved* - *_Click Here_*
> > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9
> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>>
>
>
>
>
>
>
> ____________________________________________________
> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9> /IncrediMail/
> - *Email has finally evolved* - *_Click Here_*
> <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>
|
|
From: Kevin B. <kev...@ma...> - 2004-04-13 16:49:19
|
It's a bad idea to assume that library code is "buggy" just because it doesn't do what you expect. In fact, the standard library is a carefully designed and extensively tested chunk of code. It is highly unlikely that a beginner poking at it in obvious (if naive) ways is going to discover a "bug" that has escaped legions of testers and developers. It is far more likely that the person in question simply doesn't understand how things work in C++, and has written their own bug. That is indeed the case here. This program is working exactly as specified in the C++ standard. The destructor for global objects are called *after* the main() function has exited. Standard I/O is not guaranteed to work at that time, although it might. Even if it does, though, since it will happen after the system() call in any case, you might well simply not notice it before the console window disappears. --- Kevin |
|
From: Per W. <pw...@ia...> - 2004-04-12 23:49:52
|
No, the program doesn't end when main() returns. The desctructors for
global objects will still be called. The problem with this program is that
they are called _after_ system("PAUSE").
/Per W
On Mon, 12 Apr 2004, Scott Simontis wrote:
> Try manually calling the destructor in your code. I am not a master of
> C++, but I think I see what is going on here. The "World" class is
> global. Therefore, its life is the entire program. However, when main
> ends, the program ends. The solution here would probably to create an
> instance of the class within main or call the destructor yourself in the
> code, but I think the latter is poor programming, does anybody else know?
> Latif Dokter wrote:
>
> > here is the full code
> > #include <iostream>
> > #include <stdlib.h>
> >
> > using namespace std;
> > class World
> > {
> > public:
> > World () { std::cout << "Hello!\n"; }
> > ~World () { std::cout << "Goodbye!\n"; }
> > };
> >
> > World TheWorld;
> >
> > int main(int argc, char *argv[])
> > {
> >
> > system("PAUSE");
> > return 0;
> > }
> >
> > /-------Original Message-------/
> >
> > /*From:*/ Scott Simontis <mailto:age...@co...>
> > /*Date:*/ 04/12/04 10:55:55
> > /*To:*/ Latif Dokter <mailto:ld...@op...>
> > /*Subject:*/ Re: [Dev-C++] Buggy standard library?
> >
> > Did you call the destructor?
> > Latif Dokter wrote:
> >
> > > I am using Dev.C++ 4.9.8.7 When creating a program with class World
> > > where World () {} says Hello and ~World() {} says goodbye World
> > > TheWorld; when compiled and executed
> > > in Ms dos console the program prints hello but doesn't print goodbye I
> > > have read that I may have a buggy version of the standard library if
> > > so is there a patch if not what is happening and how can I fix it
> > >
> > >
> > >
> > >
> > > ____________________________________________________
> > > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9
> > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>> /IncrediMail/
> > > - *Email has finally evolved* - *_Click Here_*
> > > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9
> > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>>
> >
> >
> >
> >
> >
> >
> > ____________________________________________________
> > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9> /IncrediMail/
> > - *Email has finally evolved* - *_Click Here_*
> > <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: <or...@vp...> - 2004-04-13 09:29:11
|
Per Westermark wrote:
> No, the program doesn't end when main() returns. The desctructors for
> global objects will still be called. The problem with this program is t=
hat
> they are called _after_ system("PAUSE").
Indeed :)
After system("PAUSE"), World gets destroyed correctly, however it cannot=20
be "seen", as the dos prompt disappears :)
If it is run from a separate dos prompt, this is what we get:
--
Hello!
Press any key to continue . . .
Goodbye!
--
The expected behaviour.
--
Greetings,
Bal=E1zs
|