I assume if you're asking if it it makes two unrelated pointers equal, not addresses of pointers. And yes, it does. And that's why it is an option - you can disable if you don't like hit.
Not sure what are you asking about my example? How can ptr() point anywhere than big() function? Look at the disassembly - there's no way it can point into middle of foo() and still return value 100000.
Oh sorry, my bad. Not your example, I mean something like this:
int Foo() { return 1000; } int Bar() { DoSomeOtherThing(); return Foo(); } // Some other place int (*f)(void) = CheckSomething() ? Foo : SomeOtherFunction; // Can this point to the end of Bar?
I'm not aware of compilers doing such optimization. While technically it would be possible, my guess why that is not happening is because of multiple reasons:
many targets/architectures require function prolog/epilog code, which means Foo() beginning must have specific bytes (saving frame pointer register) which would not happen in your Bar()
optimizer often will rearrange code - mixing code for DoSomeOtherThing() and Foo(), so having Foo() directly at end of function is less likely to happen
compiler would need to remember exactly which functions end at which places - and then search for them every time function pointer is used. This can be become very expensive in large programs