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,548 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: Address identity of functions   
   06 Oct 11 11:49:39   
   
   c8e02b87   
   From: daniel.kruegler@googlemail.com   
      
   Am 05.10.2011 23:38, schrieb A. McKenney:   
   > On Oct 4, 2:23 pm, Daniel Krügler   
   > wrote:   
   >> Am 03.10.2011 20:57, schrieb Zeljko Vrba:   
   >>   
   >>> On 2011-10-02, Daniel Krügler   wrote:   
   >>   
   >>>> There are some compilers that deduce from this, that the following   
   >> program is allowed to output '1' instead of '0':   
   >   
   > [code which compares pointers to two empty functions with the same   
   > signature.]   
   >   
   >>> Did you check whether this is the case when both functions are   
   non-empty, but   
   >>> have identical code?   
   >>   
   >> I haven't but I have been told that this happens even with non-empty   
   functions   
   >> (This makes this actually of interest, because you can effectively reduce   
   the   
   >> code bloat, especially from template instantiations).   
   >   
   > 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.   
      
   That is a good example and it is interesting to note that VS2010 does   
   output   
      
   0   
   1   
   1   
      
   so local state seems to be honored for this compiler.   
      
   Nonetheless, if address identity would be given up, there would be some   
   normative statements required that ensure that this is guaranteed for   
   such examples.   
      
   But as you mention observability: It would be definitively possible to   
   construct more complex examples that won't no longer work, e.g. if   
   someone used function address values as keys of some mapping as in the   
   following example:   
      
   template   
   struct function_to_object {   
      static int data;   
   };   
      
   template   
   int function_to_object

::data;              void f() {}       void g() {}              static_assert(        &function_to_object::data != &function_to_object::data,       "Function identity violation");              This assertion would no longer be guaranteed to hold. Does anyone take       advantage of such form of function mapping?              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