473,732 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where does the header implentation get inserted

Hi, i have newbie qestion,

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?

thanks
amit

Sep 16 '06 #1
15 2292
am******@gmail. com wrote:
Hi, i have newbie qestion,

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?
In a typical implementation, the preprocessor generates an intermediate
file or data stream with header's content included inline and passes
this to the compiler.

--
Ian Collins.
Sep 16 '06 #2
On 16 Sep 2006 14:56:36 -0700, in comp.lang.c , am******@gmail. com
wrote:
>Hi, i have newbie qestion,

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 "
implementati on file into my source code?
It doesn't.

If "something" is a library, the build process will try to link with
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.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 16 '06 #3
am******@gmail. com 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

--
Posted via a free Usenet account from http://www.teranews.com

Sep 17 '06 #4
"""
It doesn't.

If "something" is a library, the build process will try to link with
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.
"""

how can it know if it is a library?
does it convert somthing.h into somthing.o and look up for it?

amit
ho
CBFalconer wrote:
am******@gmail. com 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

--
Posted via a free Usenet account from http://www.teranews.com
Sep 17 '06 #5
On 17 Sep 2006 03:27:17 -0700, am******@gmail. com wrote:
>CBFalconer wrote:
>am******@gmail. com 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
Sep 17 '06 #6
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, am******@gmail. com wrote:
CBFalconer wrote:
am******@gmail. com 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
Sep 17 '06 #7
In article <11************ *********@m7g20 00cwm.googlegro ups.com>,
<am******@gmail .comwrote:
>i think my question is misunderstood.
>suppose i declare a function in "myLib.h". that function has an
implementati on - 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 .
The language itself doesn't answer this question: the standards
just say that external linkage -exists-, and gives very minimal properties
for it, but does not say anything about how it works.

In the past, there have been C implementations for which it was
necessary to name all the source files on the compiler command line and
which interpreted all of the lines of code as necessary, so everything
had to be named at once..
In every system that I have actually used, the C compiler provided
a way to compile source seperately to some intermediate binary state,
and the implimentation provided a mechanism to merge ("link") (possibly
transforming greatly) the intermediate binary forms into a single
executable. The intermediate forms have not always been machine code
suitable for the target: sometimes they are in an assembler-style
language that the linker rewrites into machine code.

The answer to "where does it find the implementation of a function" then
becomes "where-ever you tell the implementation' s linker to look
for the the intermediate file produced by the C compiler."

It is fairly common with modern implementations that if you name
a series of source files on a single compiler command line, that
the compiler will automatically convert each of them to intermediate
form and then automatically link them together to an executable.

--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Sep 17 '06 #8
On 17 Sep 2006 03:27:17 -0700, in comp.lang.c , am******@gmail. com
wrote:
>"""
It doesn't.

If "something" is a library, the build process will try to link with
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.
"""

how can it know if it is a library?
Because thats how it was provided to you.
The header by itself is useless. It has to have a library or source
file or object or something to contain the actual code.
>does it convert somthing.h into somthing.o and look up for it?
No.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 17 '06 #9
On Sun, 17 Sep 2006 08:22:02 -0700, in comp.lang.c , Barry Schwarz
<sc******@doezl .netwrote:
>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.
Amit didn't say that, I did, immediately below the line where he asked
>>when, where and how the compiler insert the lines in "somthing.c "
implementatio n file into my source code?
... and thus in a context where "it" was utterly clear.

Your "fixing" of top-posting in fact merely screwed the post up so
that you had no idea who said what, and in relation to what.

I suggest you start again !
>>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.
Have you got a clue what you're commenting on at this point? Stop,
wander back, and read the thread again.
>>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.
And you seem to be unable to read for sense..... (though I admit I
used 'it' a bit too much. I could have more longwindedly said 'to link
the results of that second compilation')
>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.
Sure, but Amit's question was - where does the compiler get the actual
defintions of the functions from, since he _is well aware_ that
they're not in the header.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1603
by: patrick.m.lahey | last post by:
Newbie here... Ok, the following code: class Base: _count = 0 def __init__(self): self.__class__._count += 1 print dir(self)
2
3343
by: google | last post by:
The DBA duties at my company have gotten to the point where I am unable to complete them all on my own so we decided to hire a new DBA. After weeks of searching and interviewing we are coming up with zip squat. I was wondering if the recruiting agencies are just not able to find these people or if there is really just a dearth of DB2 UDB people out there who are currently in the market for a job. We are finding mainframe people but no one...
0
1158
by: sachin | last post by:
When we view any document in print preview dialog, where does it save the document? such that when me move to next/previous page where it reads the information from . If a heavy document like RTF file having images and large number of pages is viewed in PrintPreview, does it affects the system speed? What happens at application level please guid regard
1
4804
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial single-pane form GUI. I've got some stdout print statements in the code ... but I cannot find where in the world the output text is appearing. For printing I tried both: printf ("Hello world\n"); and Console::Write ("Hello World\n");
0
1958
by: Phil | last post by:
My regional setting (on Win2000) is: (General Tab)Locale = English (US) (Date Tab), short date = MM/dd/yy When I ask .Net DateFormat.ShortDatePattern, I get MM/dd/yyyy Now, where does the yyyy part come from? It looks as if DateFormat does not look in the overriden format on the Date tab and just assumes that English(US) is fixed to MM/dd/yyyy...
1
3655
by: Daniel | last post by:
where does Microsoft.Xml.Xquery live? where does Microsoft.Xml.Xquery live? all i can find is a copy of it in the sample project: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvsdev05/html/vs05c5.asp but would like to know where Microsoft.Xml.Xquery should be obtained.
9
3718
by: DanielJohnson | last post by:
I am wondering where does the value returned by main goes. Suppoes main returns some number say 42, where is it stored. Supposed a shell script call a C program and the program returns the value 42 where is this value stored in memory ?
4
1178
by: AAaron123 | last post by:
Where does the "Extreme database" come from? During a solution conversion, VS told me it needed to install the "Crystal Reports" so I inserted the disk and during the installation or conversion I got a message that implied that database was missing. How can I install that database? Thanks
0
1333
by: sanchaita | last post by:
I wanted to know where does the WPHOST.db file corresponding to the post office in a novell groupwise gets stored. Does it get stored in our local disc. If yes, then where?. And where does the novell address book gets stored? Does it gets stored in our local disc? or is present at the server side? I want to know that whether only 1 copy of WPHOST.db exist or 2 copy exit 1 at the client machine and other at the server side. For the novell...
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.