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,518 of 33,346   
   =?ISO-8859-15?Q?Daniel_Kr=FCgler?= to All   
   Address identity of functions   
   02 Oct 11 05:38:44   
   
   From: daniel.kruegler@googlemail.com   
      
   Currently the C++ core language imposes the following requirement on function   
   pointer equality (5.10 [expr.eq] p1):   
      
   "Two pointers of the same type compare equal if and only if they are both   
   null, both point to the same function, or both represent the same address   
   (3.9.2)."   
      
   This wording seems to distinguish (object) addresses from functions and it is   
   not really clear what implications can be derived from that.   
      
   There are some compilers that deduce from this, that the following program is   
   allowed to output '1' instead of '0':   
      
    #include    
      
    void f(){}   
    void g(){}   
      
    int main()   
    {   
      std::cout << (&f == &g) << std::endl;   
    }   
      
   [My thanks go to Nikolay Ivchenkov for this example]   
      
   Irrespective of whether this behaviour of those compilers would be a defect   
   according the current standard, I would be interested in code examples that   
   would no longer work, if there would be no unique address identity guarantee   
   for functions.   
      
   In which way are function address values currently used where relaxing this   
   rule would break existing or at least theoretically useful code?   
      
   Thanks & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
      
      
   --   
         [ 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