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

C++ includes

It is common recommendation that C++ header
files should be "self-sufficient", i.e. they
should directly include every concept it use
and not rely on getting this information
through other includes.

Is this the case also for source files?

Thanks!
Aug 15 '05 #1
4 1558
* Jacob:
It is common recommendation that C++ header
files should be "self-sufficient", i.e. they
should directly include every concept it use
and not rely on getting this information
through other includes.

Is this the case also for source files?


A header file is a source file: with that interpretation the question is
meaningless.

If you mean module implementation files then the question assumes that a
module implementation is #include'd in some other file, and then your
question boils down to: should module implementation files be #include'd?

And the answer to that is no.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 15 '05 #2
A source file, of course, must contain all information necessary either by
#including corresponding headers or having it as part of the file.
Generally, if something in a source is not declared before use, you won't be
able to compile it.

Ben
Aug 15 '05 #3
benben wrote:
A source file, of course, must contain all information necessary either by
#including corresponding headers or having it as part of the file.
Generally, if something in a source is not declared before use, you won't be
able to compile it.


An "include file" is declaration and protected againts
multiple includes by a include guard, right?

Consider the following two rudimentary include files:

IncludeA.h:
-----------
#include <string>
class A;
IncludeB.h:
-----------
#include "IncludeA.h"
class B {
public:
A a;
string name;
};
I would claim it as an error for IncludeB.h *NOT* to include
<string> as its declaration (B) depend on the string concept.

You don't get a compiler error nor warning (perhaps a warning
would be appropriate) by nut including it, as <string> is
included indirectly through IncludeA.

This is a common knowlegde and most styleguides will suggest
you include <string> in this case to stay independent of internal
changes in IncludeA.
My question is if this should be the case also for difinition
files (.c++ files)? You may claim that by including the declaration
"IncludeA", you inherit the lot, and there is no need to include
<string> separately as you got it for free already.

Any suggestions?

Thanks!

Aug 15 '05 #4

"Jacob" <ja***@yahoo.com> wrote in message
news:Lc********************@telenor.com...
benben wrote:
A source file, of course, must contain all information necessary either
by #including corresponding headers or having it as part of the file.
Generally, if something in a source is not declared before use, you won't
be able to compile it.
An "include file" is declaration and protected againts
multiple includes by a include guard, right?


Correct!

Consider the following two rudimentary include files:

IncludeA.h:
-----------
#include <string>
class A;
IncludeB.h:
-----------
#include "IncludeA.h"
class B {
public:
A a;
string name;
};
I would claim it as an error for IncludeB.h *NOT* to include
<string> as its declaration (B) depend on the string concept.
Correct!

You don't get a compiler error nor warning (perhaps a warning
would be appropriate) by nut including it, as <string> is
included indirectly through IncludeA.
No, you don't get a compiler error.

This is a common knowlegde and most styleguides will suggest
you include <string> in this case to stay independent of internal
changes in IncludeA.
That's correct!


My question is if this should be the case also for difinition
files (.c++ files)? You may claim that by including the declaration
"IncludeA", you inherit the lot, and there is no need to include
<string> separately as you got it for free already.
Same rule, the source file #includes "IncludeA.h" for class A, "IncludeB.h"
for class B, <string> for std::string.

Any suggestions?

Thanks!


No worries!

Ben
Aug 16 '05 #5

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

Similar topics

13
by: Tim Tyler | last post by:
A fairly simple question: I have a library A which depends on library B and C. Currently I have: <?php include("A.inc.php"); include("B.inc.php"); include("C.inc.php");
2
by: Joe Mowry | last post by:
First off, I'm posting this question for a friend that doesn't have access to the news groups. Problem: Using PHP as the base and has several PHP < includes > for various functions, all this...
4
by: Patrick | last post by:
I have an ASP site with about 50 ASP files, all of which are currently including a common "includes.asp" file near the top of the file, responsible for generating the <HEAD/> section of the HTML ...
4
by: Generic Usenet Account | last post by:
I am seeing some unexpected behavior while using the STL "includes" algorithm. I am not sure if this is a bug with the template header files in our STL distribution, or if this is how it should...
2
by: David Muoio | last post by:
I am trying to validate an XML file against an XSD that is stored in the assembly as an embedded resource. I can get it to work as long as the XSD does not include other XSDs. After a fair amount...
12
by: tshad | last post by:
I am not sure why I am getting this error: I have the following code I want to run from another include file that holds all my functions. functions.inc...
6
by: William F. Zachmann | last post by:
We've got a project going that involves moving an old web site with a massive dll written in C++ that produces most of the output from a SQL 7.0 data base on NT4 onto IIS on Windows 2003 Server...
3
by: Jeff | last post by:
I have an asp page. Now I know this is sortof OT, but I am not sure of the forum to get an answer. I have an include on this asp page <!-- #include file=\forum\includes\consts-inc.asp --> ...
4
by: Ron | last post by:
Hi all, Trying to work out a few problems in using php on my site. Partially this is a html question. I was reading a lot of the posts and it seems that some of the includes people are using are...
1
by: JRough | last post by:
I have includes at the top of the file and I have inline includes also includes in mysql queries. For example: include './includes/config.inc.php'; include $include_path.'dates.inc.php';...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.