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

From: Ioannis Vranos (ivr_at_remove.this.grad.com)
Date: 03/30/05


Date: Wed, 30 Mar 2005 16:07:13 +0300

fabio de francesco wrote:

> 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?

It is permitted. What you are incrementing above is the value stored in variable a.

Also check this:

#include <iostream>
#include <cstdlib>
#include <csignal>

inline void SigSegVHandler(int signal)
{
     using namespace std;

     cerr<<"Illegal memory operation!\n"<<"Exiting...\n";

     exit(EXIT_FAILURE);
}

int main()
{
     using namespace std;

     signal(SIGSEGV, SigSegVHandler);

     int *p= 0;

     ++(*p);

     return 0;
}

-- 
Ioannis Vranos
http://www23.brinkster.com/noicys


Relevant Pages

  • Re: Class hierarchy of exceptions (Ada, C++)
    ... fabio de francesco wrote: ... > void fun() ... > int main ... > Shouldn't it have to complain? ...
    (comp.lang.ada)
  • Re: Problems with main method <identifier> expected
    ... method that the JVM calls when it starts your program. ... it will complain and your program won't run. ... > of precision, and I'm told theere's a int somewhere, but there isn't ... compiler trusts you, and stops trying to guard your footsteps. ...
    (comp.lang.java.help)
  • Re: Unary +
    ... which the cplr will complain about. ... than int will cause promotion of that int. ... equal sizeof +c. ...
    (comp.lang.c)
  • Re: byte + byte -> int
    ... is in range for an int, but allows the line ... it thinks precision might be lost in a down-conversion. ... decimal places when converting from double to float -- that's loss of precision. ... complain about, so we're stuck with it ... ...
    (comp.lang.java.programmer)
  • Re: The importance of prototypes
    ... >> Without using a prototype, if you have a function that takes a double ... >> argument, and you pass it an int, you must cast the int to double. ... Would the compiler have to complain about this? ... The compiler is not obligated to complain about either call. ...
    (comp.lang.c)