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,546 of 33,346    |
|    Francis Glassborow to A. McKenney    |
|    Re: Address identity of functions    |
|    06 Oct 11 11:33:43    |
   
   c8e02b87   
   From: francis.glassborow@btinternet.com   
      
   On 05/10/2011 22:38, A. McKenney wrote:   
      
   > What about:   
   >   
   > #include   
   >   
   > int f(){ static int i = 0; return ++i; }   
   > int g(){ static int i = 0; return ++i; }   
   >   
   > int main()   
   > {   
   > std::cout<< (&f ==&g)<< std::endl;   
   > std::cout<< f()<< std::endl;   
   > std::cout<< g()<< std::endl;   
   > }   
   >   
   > f() and g() have identical code, but you would   
   > certainly be able to tell if it was treating f() and   
   > g() as the same function.   
   >   
   >   
   But only if you look :) I think that this is a quantum property of code,   
   if you never check the addresses might be the same but as soon as you   
   check the compiler must ensure that the addresses are different. Note   
   that you could see that the compiler had collapsed the code by examining   
   the generated object code but that is not the same thing as being able   
   to check from within the program.   
      
      
      
      
   --   
    [ 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