Re: How C compilers handle multiple function definitions.

"Armel" <armelasselin@hotmail.com>
Mon, 29 Dec 2008 17:20:28 +0100

          From comp.compilers

Related articles
How C compilers handle multiple function definitions. typingcat@gmail.com (RealCat) (2008-12-28)
Re: How C compilers handle multiple function definitions. armelasselin@hotmail.com (Armel) (2008-12-29)
Re: How C compilers handle multiple function definitions. mburrel@uwo.ca (Mike Burrell) (2008-12-29)
Re: How C compilers handle multiple function definitions. gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-12-30)
Re: How C compilers handle multiple function definitions. kamalpr@hp.com (kamal) (2009-01-01)
Re: How C compilers handle multiple function definitions. kamalpr@hp.com (kamal) (2009-01-01)
| List of all articles for this month |

From: "Armel" <armelasselin@hotmail.com>
Newsgroups: comp.compilers
Date: Mon, 29 Dec 2008 17:20:28 +0100
Organization: les newsgroups par Orange
References: 08-12-107
Keywords: linker, comment
Posted-Date: 29 Dec 2008 15:52:19 EST

"RealCat" <typingcat@gmail.com> a icrit
> If there are functions whose names are the same in object files and
> library files, what should happen during the compliation? Should this
> always cause a link error, or can C compilers make assumptions such
> as : "function definition in the object file has higher precedence
> over the one in the library file" or "the one in the previously linked
> library file has higher precedence over the ones in the library files
> linked later."?
> Is there any standard behaviour for this case or does it vary with
> compiler implimentations?


from what I could see:
- a library is mostly just the concatenation of several objects(=modules),
so all the treatments are 'as if' the objects where provided in library
build order, making a library _does not_ resolve references.
- libraries which intend to let some functions be overriden are built in a
"one function per object/module" fashion, actually solving the above
question.


It seems that there is no real standard shared by all _linkers_ but
the "one function per object" paradigm makes your question simple
enough to be sure that the _first_ "function module" is considered the
one to choose


this technic is often used to override the 'malloc' function and add some
debugging front end to it, while ensuring the linker will use your own
version (listed before the -l of C library) is called by the C library
itself.


HIH
Armel
[That's one way to do it. More typically the library has a directory
that the linker can use to decide what modules to use without having
to read through the entire library. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.