473,396 Members | 2,158 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,396 software developers and data experts.

Understanding Separate Compilation

Hi
I am trying to understand separate compilation and how to set up
simple Makefiles. This is my question:

Say I have a simple 'nonmain' sourcefile. Just a couple of functions, not
longer than 10 lines alltogether. I wondered if it's possible to combine
this source file with its header file into a single file (nonmain.h).
Is this "bad practice"? For some reason, having a
separate header for such a simple source file seems like an overkill.
Thnkas for your help.

Oct 8 '05 #1
1 2687
Frankie Montenegro wrote:
Hi
I am trying to understand separate compilation and how to set up
simple Makefiles. This is my question:

Say I have a simple 'nonmain' sourcefile. Just a couple of functions, not
longer than 10 lines alltogether. I wondered if it's possible to combine
this source file with its header file into a single file (nonmain.h).
Is this "bad practice"? For some reason, having a
separate header for such a simple source file seems like an overkill.
Thnkas for your help.


Sure you can. When you #include a header file, the compiler
(preprocessor) just copies its contents into the including file. If you
want to do it yourself you can.

However, if you intend to have more than one source file (translation
unit) include the same header then it's important that that header not
contain any function definitions that aren't declared inline or
templates. Otherwise the linker will object to this violation of the
one definition rule (ODR).

If you're just writing a small standalone application and don't intend
to use its contents anywhere else then it's certainly convenient to have
everything in one file (most people would name this *.cpp, not *.h).
But since you call your file 'nomain' I infer that this is not a
standalone program and you should then be careful about violating the ODR.

Mark
Oct 8 '05 #2

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

Similar topics

7
by: laura | last post by:
I'm trying to understand fully Server.MapPath. I am writing an intranet for a small company and want to be able to put some files accessible to all, hyperlinked from the intranet and therefore,...
6
by: Paul Fame | last post by:
Hello World, This is not a flame, but a question about the fundamentals of the language. Unlike some languages, C++ requires class member functions to be declared twice: once in the class...
1
by: wpy | last post by:
I wrote aspnet application with code behind then compile it to dll. The web application will use class library dll that I wrote. After compilation, the library dll and interface dll will put...
6
by: mister.mwa | last post by:
Hello, I have the following problem: I have a class Foo, and a class Bar. I want Foo to inherit from Bar, but i want to put them in separate files Foo.vb and Bar.vb. Then i will use the Foo...
1
by: Sergei Shelukhin | last post by:
Hi. We have a resource assembly that is separate and is used by a class library assembly, a web app, web service set (all in separate projects). Windows app is also potentially possible. First...
3
by: Blasting Cap | last post by:
I am working on a web app that I want to be able to use a separate config file on, in addition to the web.config file that's already working in the application. If I put the following in the...
1
by: vinnie | last post by:
I'm learning how to build web application with asp.net 2.0, and while the author of the book clearly invite the reader to place the code in a separate file if building a web form, he place the code...
0
by: Steve | last post by:
Hello- Your assistance with this issue is greatly appreciated. Environment: - Load-balanced IIS 6.0 servers (Win2003) - web servers point (via UNC path) to a Microsoft File Cluster on...
6
by: Jeff Newman | last post by:
Hello, Could anyone explain to me why the following class's destructor shows up as having multiple branches? (At least as judged by gcov 4.1.2 when compiled with gcc 4.1.2 ): struct blah {...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
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.