473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Seperate compilation (header files n' their implementations)

Seperate compilation (that's what it's called, right?) seems to be
quite popular, so I decided to get some info about it, and (d'oh) use
it...

But it's whole structure seems weird to me...

Here's what I think of how it is (from what I've read):

THE PROJECT
+1st header file
+Implementation of the 1st header file (includes the header file)
+2nd header file
+Implementation of the 2nd header file (includes the header file)
........
+Nth header file
+Implementation of the Nth header file (includes the header file)
+MAIN program which includes the header files

I guess the above structure is correct...

But here's what I don't understand...

Since the main program includes the header files, it only has the
interfaces and not the implementations of the headers (since the
implementations are in the .cc files, and not in the .h files).

But the headers DON'T include their implementations; the opposite
though does happen...

So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????

And how would I compile such a project? For example, let's say I
compile the main program... Whatever will happen of the
implementations???

Thanks in advance and for your patience,
cmad
Jul 22 '05 #1
3 2196
"Chris Mantoulidis" <cm****@yahoo.com> wrote...
Seperate compilation (that's what it's called, right?)
I always thought it was spelled "sepArate compilation"...
seems to be
quite popular, so I decided to get some info about it, and (d'oh) use
it...
What's the "d'oh" about? Did you mean "duh" instead of "d'oh"?

But it's whole structure seems weird to me...

Here's what I think of how it is (from what I've read):

THE PROJECT
+1st header file
+Implementation of the 1st header file (includes the header file)
The correct way of saying would be:

1st header: definition of the 1st class and related declarations
1st translation unit: definitions of 1st class members and other
related objects/functions.
etc.
+2nd header file
+Implementation of the 2nd header file (includes the header file)
.......
+Nth header file
+Implementation of the Nth header file (includes the header file)
+MAIN program which includes the header files

I guess the above structure is correct...
Depends on how you look at it.

But here's what I don't understand...

Since the main program includes the header files, it only has the
interfaces and not the implementations of the headers (since the
implementations are in the .cc files, and not in the .h files).
That's basically what it boils down to, yes.

But the headers DON'T include their implementations; the opposite
though does happen...
Headers _contain_ declarations and class definitions. They don't
include anything.

So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????
It's _linked_ at the _linking_ stage of building the program.

And how would I compile such a project?
Just like you said in te beginning, _separately_.
For example, let's say I
compile the main program... Whatever will happen of the
implementations???


You compile them too.

I guess you need a decent book that describes how to use your
compiler/linker/librarian programs. It very much depends on what
compiler/platform you're using. And it pretty much goes beyond the
scope of this newsgroup. I recommend asking in a newsgroup for
your compiler.

Victor
Jul 22 '05 #2
Chris Mantoulidis writes:
So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????


The linker knows where the libraries are, it found out by some magic when
the compiler was installed/whatever.
Jul 22 '05 #3
cm****@yahoo.com (Chris Mantoulidis) wrote in message
Since the main program includes the header files, it only has the
interfaces and not the implementations of the headers (since the
implementations are in the .cc files, and not in the .h files).

But the headers DON'T include their implementations; the opposite
though does happen...

So how can the program be aware of the implementations since it seems
like the .cc files are nowhere included??????

And how would I compile such a project? For example, let's say I
compile the main program... Whatever will happen of the
implementations???

Thanks in advance and for your patience,
cmad

It sounds like you lack a real understanding of how a binary is
produced from source code. There are two steps, compilation and
linking.

In compilation, the code is validated by the compiler and translated
into blocks of machine code called object files. The compiler does
not care how the functions in other blocks are implemented. Header
files are the interface between the blocks and the compiler simply
validates how you call a function against how this function is defined
in the header.

The compiler will only complain if it finds a function call and no
matching declaration for this function--for good reason. A mismatch
may indicate a typo or other syntatical error in your code.

Once an object file exists for each block of code, a single executable
is produced. It is at this point where all of the function calls and
implementations are connected--linked--together. If you have a
function that is defined and not used, *and* if you call that function
somewhere in the code it will not be noticed until this step.

There are TONS of resources available to read up on this. Try google.

---
Jared Dykstra
http://www.bork.org/~jared
Jul 22 '05 #4

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

Similar topics

11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
12
by: blueblueblue2005 | last post by:
Hi, here is an example I copied from Deitel C++ book. but when I compile it, always get the above compilation error, no matter how I change the include order, please help. here is the files:...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
12
by: wanghz | last post by:
Hi, Could I ask some questions about the conditional compilaion? Suppose I have three simple files: a.c, b.c and c.h /* --------a.c--------- */ #include <stdio.h> #include "c.h" int...
5
by: Mikael S. H. | last post by:
Header file compilation I'm coding a small irc bot, and I've noticed that compilation takes very long when I add certain header files (compared to compilation time without). I've tried to find...
5
by: jayceechong | last post by:
If I write my own C compiler, can I just "take" existing standard header files (e.g. stdio.h, stdlib.h, etc.) from an existing C compiler and plug them in my own? I understand I have to write my...
7
by: ben | last post by:
Hi, I have few doubts about header files. Is it true that header files always have only "function declaration" and not definition? Next where can i find definition of functions defined in...
7
by: Wei | last post by:
Hi all, I found out I can use the max function which is defined in STL <algorithmwithout including this header in my program. The compilers I used are GNU g++ 3.4.4 and Visual Studio C++ 2005. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.