Ron Garret <rNOSPAMon@flownet.com> wrote:
| The requirements as given required this kind of a hack. You're saying
| that dynamically binding functions that have been defined in the normal
| way is a bad idea. I do not disagree. But Rob claimed it couldn't be
| done, and that's not true.
Actually, it *is* true, in the sense of "can't be done portably or
in a standard-conformant way", if the functions being redefined were
compiled elsewhere. Consider functions FOO & BAR in a separate file,
where BAR calls FOO and you try to rebind FOO:
CHLS 18.104.22.168 Semantic Constraints
A call within a file to a named function that is defined in the
same file refers to that function, unless that function has been
declared notinline. The consequences are unspecified if functions
are redefined individually at run time or multiply defined in
the same file.
The most likely and benign [and yet still "wrong"] consequence
is that the code for BAR has the absolute machine address of
FOO's machine code compiled into its body, and any redefinition
or shadowing of FOO *won't* change which code is actually
called by BAR.
Worse, if FOO *was* declared "inline", then this one [loc. cite]
prohibits it entirely:
The definition of a function that is defined and declared inline
in the compilation environment must be the same at run time.
There are other constraints in that section which limit what you
may change at run-time in a portable and standard-conformant way.
Again, my commments were/are in the context as I perceived it
of the OP's initial request, which was for a way at run-time to
individually override arbitrary functions in some random library
he'd loaded [a library written/provided by others]. It is *that*
which I was claiming "can't be done" in general, and probably not
in *any* implementation with a decent file compiler.
Rob Warnock <firstname.lastname@example.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607