Re: overriding functions
- From: Eric <eric@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 02 Jun 2005 16:43:46 -0500
Cool. That settles it for me then.
Thanks eric
Eric Sosman wrote:
Eric wrote:
I have a program that uses a custom function that, as it happens, has the same name as a function in the standard library. By custom, I mean it was something that was written in-house because at the time this function did not exist in the standard library (as near as I can tell).
In general, how confident can I be that the resulting executable will use my custom function rather than the libc version of the function?
"In general," not very. Some systems will use yours, some systems will use their own, some will use both in a strange sort of mixture, and some will refuse to link the program in the first place.
(In particular, all of this is happening on a stock RH9 machine).
Then it's probably possible to get "something reasonable" to happen, but how you go about it (and how you verify that you got what you expected) are questions you should ask on a newsgroup devoted to RH, not here.
Would I be much better off just renaming the custom function and all its references?
Yes, unequivocally. You'll also ease your maintenance burden, perhaps by a lot. A programmer who sees a call to what he thinks is a Standard library function will assume he knows what the function does; if it actually turns out to do something different, he will misunderstand what the program is trying to do and will waste time and effort on blind alleys.
From what I've been able to piece together, it sounds like resolving conflicting functions is kind of a crap shoot and that I should just avoid function name conflicts.
That's the best policy, I think. One might be tempted to use #define to accomplish the renaming, but that would probably turn out to be at least as disruptive as just doing a wholesale edit -- and would still leave the "confusion issue" unsolved.
I once tracked down a nasty bug where a large program was crashing unpredictably inside the memory allocation functions. The cause turned out to be a realloc() of some memory obtained from malloc() -- all perfectly legal, and everything should have worked just fine. It turned out that the whole program was using #define's to substitute its own implementations of malloc() and friends, but that one module had been overlooked when somebody went around inserting them -- maybe the module hadn't been doing any memory management back then. The effect of allocating memory with local_malloc_lookalike() and then trying to resize it with the One True realloc() is best left to your morbid imagination.
.
- References:
- overriding functions
- From: Eric
- Re: overriding functions
- From: Eric Sosman
- overriding functions
- Prev by Date: Re: overriding functions
- Next by Date: Re: Some pointer quiestions again
- Previous by thread: Re: overriding functions
- Next by thread: Re: overriding functions
- Index(es):
Relevant Pages
|
|