Ian Collins wrote:
Fr************@googlemail.com wrote:
>This may well be implementation-defined or undefined behavior... if
so, then of course that's a good enough answer.
[... module A aims a function pointer at strcmp, module B
uses the pointer ...]
Is the function2 guaranteed to invoke strcmp? In other words, are
addresses of standard library functions guaranteed to be constant
across different files?
There will only one instance of any function with global scope.
How can a program detect the number of "instances" of
a function? It can, extending Francine Neary's sample, form
a lot of pointers to a function and then compare them, and
for Standard library functions I believe they will always
compare equal (7.1.2p6 says Standard library function names
have external linkage, and equality should follow).
But pointer comparisons can only detect the particular
"instances" that the pointers point to, and can't tell whether
other "instances" are the same or are separate. That is,
there might be forty-two copies of strcmp() lying around in a
program, forty-one of them expanded in-line at the points of
call and another compiled separately to be a target for all
those pointer variables. I can't find any explicit permission
for an implementation to make Standard functions `inline', but
I can't find a prohibition, either.
Fifteen or more years ago there was a thread about whether
the expression `memcpy == memmove' could be true. I recall that
the debate went on for quite a while, but I don't recall it coming
to a definitive conclusion.
At any rate: Francine Neary's function pointer will at the
very least point to "a" strcmp, even if not to "the" strcmp.
--
Eric Sosman
es*****@acm-dot-org.invalid