Re: Class hierarchy of exceptions (Ada, C++)
From: fabio de francesco (fmdf_at_tiscali.it)
Date: 03/30/05
- Next message: Daniel Schüle: "Re: Why assembly and translation"
- Previous message: Daniel Schüle: "Re: For what reasons?"
- In reply to: fabio de francesco: "Re: Class hierarchy of exceptions (Ada, C++)"
- Next in thread: Jean-Pierre Rosen: "Re: Class hierarchy of exceptions (Ada, C++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Daniel Schüle: "Re: Why assembly and translation"
- Previous message: Daniel Schüle: "Re: For what reasons?"
- In reply to: fabio de francesco: "Re: Class hierarchy of exceptions (Ada, C++)"
- Next in thread: Jean-Pierre Rosen: "Re: Class hierarchy of exceptions (Ada, C++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|