Ian Collins wrote:
> Zorro wrote:
> > Zorro wrote:
> >
> >>The simplicity of stack unraveling of C++ is not without defective
> >>consequences. The following article points to C++ examples showing the
> >>defects. An engineer aware of defects can avoid hard-to-find bugs.
> >>
> >>http://distributed-software.blogspot...defective.html
> >>
> >>Regards,
> >>
> >>http://www.zhmicro.com
> >>http://distributed-software.blogspot.com
> >>http://groups-beta.google.com/group/...Z?lnk=la&hl=en
> >
> >
> > This is a common reply to several comments, respectfully.
> >
> > 1. The use of one or another header file is cosmetic for this example.
>
> It may or may not be cosmetic, but is asking for flak.
>
> > 2. When you say a correct compiler will do better, please specify the
> > compiler.
>
> Changing you example to standard C++:
>
> #include <iostream>
>
> struct simple
> {
> int s;
> simple() { s = 5;}
> ~simple(void) {std::cout << "Destructor ..." << std::endl;}
> };
>
> int main(){
> int i = 1, j = 0;
> try {
> simple spl;
> throw 0;
> }
> catch(...) {
> std::cout << "Caught it" << std::endl;
> }
> std::cout << "Finishing" << std::endl;
> return 0;
> }
>
> any compiler should give the correct result. If not, it is broken.
>
> > 3. Division by 0 happens at system level and is not necessary to turn
> > it into a throw.
>
> Then why use it in your examples?
>
> > 4. For this example, the compiler is Microsoft Visual C++ version 6.
>
> Old and not very compliant.
>
> > 5. The defect is in the technique used. Of course it can be corrected.
> > Show me a compiler that has in fact corrected this problem. The point
> > is that, it takes a great deal beyond plain stack unraveling to correct
> > this problem.
>
> Show me one that exibits it.
>
> > 6. If you are not familiar with the concept, and do not see the real
> > issue, avoid revealing it.
> >
> Which concept?
>
> --
> Ian Collins.
Ian, the stream library for output is not the issue. I only tried to
write less because that was not the point. However, you are replacing
division by 0 with a throw. What the example is speaking of is about
exceptions that can happen without you throwing them. Although I am not
saying that your version does not fail.
The concept I am referring to is exceptional events that can happen as
your program executes. For instance, the operating system does not die
on a division by 0. It simply aborts your program. Thus, the point is
that, a C++ compiler's run-time library must sense and report such
events to your program so you can do something about them. Indeed, in
this example the compiler does report. The problem is the way the
run-time library is handling the recovery, known as stack unraveling.
One needs to do a few more things as housekeeping besides popping the
stack, and passing the exception to the next call.
Thanks for your comment.
Regards,
http://www.zhmicro.com
http://distributed-software.blogspot.com
http://groups-beta.google.com/group/...Z?lnk=la&hl=en