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 31,642 of 33,346   
   Carlos Moreno to Joshua Maurice   
   Re: Reference to show that if (this == N   
   08 Nov 11 00:06:25   
   
   e55d6642   
   From: moreno_news@mailinator.com   
      
   On 11-11-07 06:32 PM, Joshua Maurice wrote:   
      
   > In the OP's case,   
   > hiding behind a pedantic technicality asking for a citation misses the   
   > entire point.   
      
   Wait a second --- notice that I said I'm trying to convince   
   someone that the trick invokes undefined behaviour;  but the   
   thing is, his argument is that he got the idea from C++ books   
   (not sure which one(s), as I don't recall seeing the technique   
   in books), found it to produce simpler code than the alternative,   
   and it simply *works* on every existing compiler  (well, I should   
   probably add that it is likely that it works on every existing   
   compiler).   
      
   So, it does make sense that he invited/challenged me to show   
   him a reputable reference that states that the technique is   
   not legal.  (I mean, we have to agree that those aspects in   
   the above paragraph, put together, constitute quite solid   
   evidence in favor of using the technique).   
      
   And when you think about it, it is *conceivable* that the standard   
   could have specifically indicated that accessing nonstatic data   
   members (and only that) through a NULL pointer is what causes   
   undefined behaviour  (though I guess barely conceivable, in that   
   this indirectly deals with compiler implementation issues, and   
   the standard tends to be agnostic about those).   
      
   Still, it seems quite shocking that the standard would not   
   explicitly say something about accessing any member through   
   dereferencing a NULL pointer.   Or, for that matter, simply   
   stating something about dereferencing a null pointer.  I   
   mean, for example, what would be the wording that states   
   that the following is undefined behaviour:   
      
   int * p = NULL;   
   int a = *p;   
      
   How would that wording (which I'm sure there has to be some   
   *explicit* statement about the undefined-behaviour-ness of the   
   above) not be general enough to cover the use of a NULL pointer   
   to invoke a method on the pointed (inexistent) object as well??   
      
   Thanks,   
      
   Carlos   
   --   
      
      
         [ 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