473,769 Members | 5,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2228
"Chris Mantoulidis" <cm****@yahoo.c om> 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.co m (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
2763
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 understand the objective. This example may represent an interface in need of a bit of refactoring, but it goes to demonstrate the basic idea as I understand it. http://developer.kde.org/documentation/library/cvs-api/kdevelop/html/ast_8h-source.html...
11
2472
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 difficult to understand. I've described it as GOTO's on steroids, and that's what it is!. One argument against abolishing it it that it is useful for conditional compilation when porting code, etc. Well, it seems to me C++ supports that...
12
12875
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: Note: this is to practice Proxy classes. // Implementation.h class Implementation {
60
8317
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 associated with this source file For example, in a file hello.c: #include <stdio.h>
12
2503
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 main()
5
5860
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 out if it is possible to compile a header file, yet I have only found that it is possible, but not how it is done. I have RTFM, STFW and searched USENET, yet I have only found a document saying "just write `g++ file.h`, and it'll work".
5
1979
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 own library implementations, but what about these header files? Thanks!
7
2188
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 system header files. I'm working on UNIX. Thanx in advance.
7
2606
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. The program is as follows: #include <iostream> //#include <algorithm <-- I don't have to include <algorithmin
0
9423
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
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
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...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.