Re: where does the header implentation get inserted



i think my question is misunderstood.

suppose i declare a function in "myLib.h". that function has an
implementation - lets say
that that implementation is in "myLib.c"

now if i put the line #include "myLib.h" into some code, i can use the
function of "myLib" in that code. i understand where its get the
function declaration (it's copy the lines of myLib.h into my source
code, in one way or another).
what i dont understand is where it's getting the actual function
implementation.

thanks
amit

all

Barry Schwarz wrote:
On 17 Sep 2006 03:27:17 -0700, amit.man@xxxxxxxxx wrote:

CBFalconer wrote:
amit.man@xxxxxxxxx wrote:

when i write

#include <somthing.h>

the precompiler subtitue that line with the lines from "somthing.h"
header file.
when, where and how the compiler insert the lines in "somthing.c"
implementation file into my source code?

On the fly, during reading of the source file. It need not insert
anything, it just has to act as if it did so.

--
"The most amazing achievement of the computer software industry
is its continuing cancellation of the steady and staggering
gains made by the computer hardware industry..." - Petroski


Top posting fixed. Please place your response after (or interspersed
with) the text you are responding to.

"""
It doesn't.

It doesn't what? What is "it" that doesn't? What does "it" refer to?
What process should "it" be performing.


If "something" is a library, the build process will try to link with

If "something" is a library, it cannot be the object of a #include
directive. Libraries contain object code which will be processed by
the linker. #include works during preprocessing and deals only with
text that will become part of the source to be processed by the
compiler.

that library to extract the machine code needed to provide the
functions. If "something" is another source file, you will need to
tell the compiler to compile it too, and then tell the linker to link
it.

You do not tell the linker to link source.

When you #include "something", the preprocessor forces the compiler,
in a system specific manner, to process the contents of "something" at
the point in your source where the #include directive was encountered.

One common method of achieving this is to copy your source into a
temporary file line by line, substituting all the lines of "something"
instead of copying the #include line. Thus, the compiler never really
processes the #include or the file it refers to. It sees only the
single file resulting from the preprocessing.

It is fairly common for headers to not include object definitions or
executable statements. They usually consist entirely of type and
object declarations, function prototypes, and macro definitions. In
this case, the result of compiling this text does not produce anything
the linker cares about.

Even if "something" does contain executable code or object
definitions, the result of compiling its text is part of the object
code built from your source file. The linker know to process this
additional object code the same way it knows to process any of your
object code.

"""

how can it know if it is a library?

The compiler never sees a library. The #include directive does not
refer to a library. Libraries are processed at link time. How the
linker knows which libraries need to be searched for external
functions your code references is system specific.

does it convert somthing.h into somthing.o and look up for it?

The text from "somthing" is processed as part of your source and any
resulting object code is part of your object file. somthing.o is a
system specific result of processing somthing.c, not somthing.h. In
this case, somthing.c must be the translation unit and not a #include
file. If you compile x.c and #include "somthing.c", the resulting
object file will be called x.o.

Not all systems use the .o naming convention. Mine doesn't even use
the .c convention.


Remove del for email

.



Relevant Pages

  • Re: Defining many classes in a single file
    ... And one can declare just as many in a header file. ... Another reason for one class one file is due to linker ... smallest resolution. ... In this case, you can have libraries. ...
    (comp.lang.cpp)
  • /ports/multimedia/gstreamer-plugins80/ fails
    ... checking for C compiler default output file name... ... checking whether we are using the GNU C compiler... ... checking whether the cc linker supports shared libraries... ...
    (freebsd-questions)
  • gstreamer-plugins80 compile fails
    ... checking for C compiler default output file name... ... checking whether we are using the GNU C compiler... ... checking whether the cc linker supports shared libraries... ...
    (freebsd-questions)
  • Newbie packages question
    ... checking for gcc... ... checking for C compiler default output file name... ... checking if the linker is GNU ld... ... checking how to recognise dependent libraries... ...
    (Debian-User)
  • Re: resolving linker errors
    ... solution and the files also become visible in solution explorer. ... file to your linker settings (look for "additional libraries" in the input files ... compiler finds the files even when they are not in the solution. ...
    (microsoft.public.vc.language)