Re: Class hierarchy of exceptions (Ada, C++)

From: fabio de francesco (fmdf_at_tiscali.it)
Date: 03/30/05


Date: 30 Mar 2005 05:16:07 -0800


fabio de francesco wrote:
> Peter Koch Larsen wrote:
>
> > "Tapio Kelloniemi" <spam17@thack.org> skrev i en meddelelse
> > news:IQX1e.4368$sO2.1682@reader1.news.jippii.net...
>
> > > Such mistakes as using a pointer to nothing and writing past the
> array
> > > bounds don't often happen in Ada.
>
> > What makes you believe they happen regularly in C++?
>
> > I see no real difference here between a good-quality C++ compiler
and
> Ada.
>
> > > Tapio
>
> > /Peter
>
> Is the following permitted in C++?
>
> // file point.cpp
>
> #include <iostream>
>
> int *p = 0;
>
> void fun()
> {
> int a = 1;
> p = &a;
> }
>
> int main()
> {
> fun();
> ++(*p);
> std::cout << *p << '\n';
> return 0;
> }
>
> My compiler (GCC-3.4.1) doesn't raise any error with "g++ point.cpp
> -Wall -W".
>
> Shouldn't it have to complain?
>
> fabio de francesco

The following is more enjoable:

#include <iostream>

int *p = 0;

void fun()
{
    int a = 1;
    p = &a;
}

int fun2()
{
    int b = 2;
    return b *= b;
}

int main()
{
    fun();
    int c = fun2();
    ++(*p);
    std::cout << *p << '\n';
    std::cout << c << '\n';
    return 0;
}

[toor@myhost]$ g++ point4.cpp -Wall -W
[toor@myhost]$ ./a.out
5
4

And now, trying to change some output statements:

int main()
{
    fun();
    int c = fun2();
    std::cout << c << '\n';
    ++(*p);
    std::cout << *p << '\n';
    return 0;
}

[toor@myhost]$ g++ point4.cpp -Wall -W
[toor@myhost]$ ./a.out
4
12247261

I don't like anymore spending precious time with debuggers.

Ciao,

fabio de francesco



Relevant Pages

  • Re: Class hierarchy of exceptions (Ada, C++)
    ... fabio de francesco wrote: ... > void fun() ... > int main ...
    (comp.lang.ada)
  • Re: Fibonacci via binrec combinator
    ... including 0 ms collecting ... (define (fun x) ... int main; ... struct rectangular; ...
    (comp.lang.scheme)
  • Re: questions
    ... will it default to int??? ... char fun() ... there is a sequence point after evaluation of the left operand. ... Since 'i' is non-zero, the right operand of the && expression must be evaluated, resulting in a recursive call to fun. ...
    (comp.lang.c)
  • Re: Obstacles for Tcl/Tk commercial application development ?
    ... Whenever there was a problem in a Tcl program, it was not related to the type system and would have occurred in any static language as well - but eventually much worse. ... "Simple typos" will come back to you as soon as you run your procedure the first time for testing. ... int fun { ...
    (comp.lang.tcl)
  • Re: ML simple while loop problem(deleting VAL ID)
    ... with resultp. ... fun prompt p = ... "int" in while-loop. ... int ref * int ref list ...
    (comp.lang.functional)