Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,127 of 33,346    |
|    kawninzx6@googlemail.com to All    |
|    dynamic_cast undefined behavior    |
|    19 Jul 13 17:02:21    |
   
   Hi C++ experts,   
      
   Is it ever safe to dereference a NULL pointer? Specifically,   
   I'm curious about dereferencing NULL during dynamic_cast.   
      
   Contrived example code:   
   // includes omitted   
      
   class BaseFoo   
   {   
    public:   
    virtual ~BaseFoo() {}   
   };   
      
   class Foo : public BaseFoo {};   
      
   void process(int& i) { ... }   
      
   void process(Foo& foo) { ... }   
      
   BaseFoo* getFoo() { ... }   
      
   int main()   
   {   
    int *i = NULL;   
    void process(*i); // (1)   
      
    try   
    {   
    process(dynamic_cast
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca