Re: Address identity of functions
Am 03.10.2011 20:57, schrieb Zeljko Vrba:
On 2011-10-02, Daniel Kr?gler<daniel.kruegler@googlemail.com> wrote:
There are some compilers that deduce from this, that the following program is allowed to output '1' instead of '0':
Which compilers? :)
Actually it should be not so important for this particular question, but VC++ 10.0 or Intel C++ 12.1 (both in in release mode) are examples.
I would like to emphasize that I would prefer to discuss just the "what if scenario", I'm not intending to scandalize any compiler behaviour here.
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).
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.
Self-modifying code (I guess an area with a big UB-sign above it :)). If you
modify f and/or g at runtime, you really do need two copies.
Could you give a simple example? The code should be complete or at least self-explaining. But I must say that an example that basically depends on UB, is not so well-suited for a discussion about the effects of code running in "standard C++ mode".
Heck, it would
also break debuggers as they usually put a breakpoint by replacing instructions
at the start of a function. So you wouldn't be able to put breakpoint on f
and g independently.
This seems not such a severe reason to me, at least not for the C++ standard, because the compiler vendor typically provides a debugger or should specify the protocol. In any case, this is completely out of the scope of the standard.
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! ]