This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fwd: null pointer dereferencing]


hi,
PFA the mail wherein I have added a code sample which seems to lead to incorrect compiled code using


>g++ -v


Reading specs from /usr/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.0.2/specs Configured with: ./configure Thread model: single gcc version 3.0.2

Please have a look and if possible do let me know too if you think it is a bug in the compiler trying to optimize.

thanks
Abhishek
--- Begin Message ---

class A{ public: A() {} ~A() {} void do_something(void){}


int b;


};

int main(){

A *a = 0;
//null pointer dereferencing!!!!!
a->do_something();


// a->b = 10; fails though return 0; }

this code works! Ganesh, this is similar to the strat log code that had same problem (CreateComp_dialog.cc) (suresh told me about it).

Only reason I can attribute to it is that the method is not changing the state of the object and a method belongs 'more' to a class than to an object. The compiler might have generated such a nasty side effect by replacing the statement by a direct call to the func instead of first de-referencing it in runtime. From a language point of view, it seems incorrect to me.

Can you provide different reasons why it should work the way it is?


thanks Abhishek



--- End Message ---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]