Re: overriding functions



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.

.



Relevant Pages

  • custom allocation and custom type
    ... I am trying to create a custom tuple type. ... custom memory region, which will be a memory-mapped file. ... I return, to ensure it lives on, but I am getting an occasional crash ... persttupleobject.o:persttupleobject.c: undefined reference ...
    (comp.lang.python)
  • Re: Is Greenspun enough?
    ... >George Neuner wrote: ... I've written several custom allocators from scratch for realtime use ... most I have ever needed to do is preallocate arrays of objects and do ... array memory to be non-pageable]. ...
    (comp.lang.lisp)
  • Re: Custom Form Memory Hole?
    ... > with their own custom form. ... > certain machines open or create a new item using these custom forms - the ... > 300K of memory up to using 200MB of memory, ... two WinXP computers (one of which is affected, ...
    (microsoft.public.office.developer.outlook.forms)
  • Re: Best way of copying a single file to multiple directories
    ... Turns out I need a custom php.ini file in each ... >directory that contains php files to sort out a default max memory ...
    (alt.php)
  • Re: Why no reset() function?
    ... Eric Sosman Wrote: ... all the stored variables and restores memory state to startup. ... that *all* allocation methods are vulnerable to fragmentation ... occur with memory only about 2/3 full, no matter what allocation ...
    (comp.lang.c)