home bbs files messages ]

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 32,993 of 33,346   
   DeMarcus to All   
   Re: What does null mean?   
   22 Apr 13 15:50:28   
   
   From: demarcus_at_hotmail_com@tellus.orb.dotsrc.org   
      
   >> If you read this code, what do you think it does?   
   >>   
   >> CameraMan cm( nullptr );   
   >>   
   >> It could mean anything, right?   
   >>   
   >> [...]   
   >>   
   >> My question is; would you all agree that nullptr is a magic number   
   >> that always should be replaced with a label like the following? const   
   >> std::nullptr_t BAD_ANGLE = nullptr;   
   >   
   > For one thing, nullptr has the general meaning of "pointee not   
   > existent". In cases where it has this meaning, there's no need to define   
   > a named constant.   
   >   
      
   I agree on that. There's no need to make it more complicated. I would   
   still initialize variables like this.   
      
   int* anglep = nullptr;   
      
   > In cases where it doesn't have this meaning, I have the suspicion that   
   > maybe one shouldn't use nullptr in the first place.   
      
   Maybe my BAD_ANGLE was a bit misleading, a better label would have been   
   ANGLE_MISSING. Your "pointee not existent" is correct information but   
   quite often not complete enough. I would like to be able to say "angle   
   pointee not existent".   
      
   Usually the problem shows up at function calls like:   
   CameraMan cm( nullptr );   
   cm.prepare( 17, "r", nullptr );   
      
   So maybe the problem isn't with the labeling but with the naming of the   
   functions. In above example it could be:   
   cm.insertReelNumber( 17 );   
   cm.setReadOnly();   
   cm.setAngle( nullptr );   
      
   But when you really must have a pointer in the constructor it's much   
   easier and explicit to read:   
   CameraMan cm( ANGLE_MISSING );   
      
      
   Maybe it's not a general rule that nullptr is a magic number but I will   
   definitely think twice when I write it to see if it obvious what it   
   represents.   
      
      
   Regards,   
   Daniel   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca