473,656 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

include paths - is there a defacto standard?

The standard doesn't define this but what conventions do projects use?

As I understand it,

#include <somelibrary. h>

is used for including system headers and those of frameworks such
as wxWidgets - and

#include "someheader .h"

is used for more application-specific things.

The VC8 docs say, #include <...searches the paths set for the
project, but #include "..." tries the dir of the file with the include,
and the file that included it etc... before it searches the project
setting include paths.

Is this a defacto standard, or do compilers implement different
ways of doing it? Is there a sort of minimal conventions programmers
stick to to be compiler-independent?
Nov 4 '07 #1
6 1746
"Ole Nielsby" <ol*********@te kare-you-spamminglogisk. dkwrote in
message news:47******** **************@ dtext02.news.te le.dk...
: The standard doesn't define this but what conventions do projects use?
:
: As I understand it,
:
: #include <somelibrary. h>
:
: is used for including system headers and those of frameworks such
: as wxWidgets - and
:
: #include "someheader .h"
:
: is used for more application-specific things.
:
: The VC8 docs say, #include <...searches the paths set for the
: project, but #include "..." tries the dir of the file with the
include,
: and the file that included it etc... before it searches the project
: setting include paths.
:
: Is this a defacto standard, or do compilers implement different
: ways of doing it? Is there a sort of minimal conventions programmers
: stick to to be compiler-independent?

The only thing defined in the standard is that "..." first searches
for a file in some (user-defined) locations and then, if not successful,
searches the same locations as for <...>.

In practice, most compilers I know handle "..." in a similar fashion
as VC8: looking for paths relative to the currently processed file.
But there is no guarantee that other compilers will do the same.

I knew some projects/guidelines that required exclusive use of <...>
and proper specification of search paths in compiler invocation.

I personally use <...for all 'absolute' files/paths referring to
(usually external) libraries, and "..." for (relative path) references
to files within the same module.

I think that this can be left as a stylistic choice...
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Nov 4 '07 #2
On Nov 4, 12:44 pm, "Ole Nielsby"
<ole.niel...@te kare-you-spamminglogisk. dkwrote:
The standard doesn't define this but what conventions do projects use?
As I understand it,
#include <somelibrary. h>
is used for including system headers and those of frameworks such
as wxWidgets - and
#include "someheader .h"
is used for more application-specific things.
The VC8 docs say, #include <...searches the paths set for the
project, but #include "..." tries the dir of the file with the include,
and the file that included it etc... before it searches the project
setting include paths.
Is this a defacto standard, or do compilers implement different
ways of doing it?
It seems pretty much the usual convention. I'm not sure that
other compilers try the directories of all of the including
files, however: most of the time, I think, it is the directory
of the file which does the include, then treat it like a <...>.
All of the compilers I know apply the /I or -I options to the
<...(and thus implicitly to the "...", since the "..." uses
the <...paths if it doesn't find the code locally). I think
some compilers have additional options which only apply to the
"..." form, as well. And of course, the only thing the standard
really says is that if the search with the "..." form fails, the
compiler should retry as if it were specified <...>.
Is there a sort of minimal conventions programmers stick to to
be compiler-independent?
The usual convention seems to work well in practice: system
headers, and anything you assimulate to system headers, use
<...>, other headers use "...". You'll probably find some
variation as to what is assimulated to system headers, however:
some places will include not only third party libraries, like
wxWidgets, but also lower level in house libraries which are
used in many different projects, where as others may not even
consider major third party libraries, limiting <...to those
libraries furnished with the compiler or bundled with the OS.

In general, I wouldn't worry about it too much, except to ensure
that local headers use "...".

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 4 '07 #3
On Nov 4, 12:57 pm, James Kanze <james.ka...@gm ail.comwrote:
On Nov 4, 12:44 pm, "Ole Nielsby"

<ole.niel...@te kare-you-spamminglogisk. dkwrote:
The standard doesn't define this but what conventions do projects use?
As I understand it,
#include <somelibrary. h>
is used for including system headers and those of frameworks such
as wxWidgets - and
#include "someheader .h"
is used for more application-specific things.
The VC8 docs say, #include <...searches the paths set for the
project, but #include "..." tries the dir of the file with the include,
and the file that included it etc... before it searches the project
setting include paths.
Is this a defacto standard, or do compilers implement different
ways of doing it?

It seems pretty much the usual convention. I'm not sure that
other compilers try the directories of all of the including
files, however: most of the time, I think, it is the directory
of the file which does the include, then treat it like a <...>.
All of the compilers I know apply the /I or -I options to the
<...(and thus implicitly to the "...", since the "..." uses
the <...paths if it doesn't find the code locally). I think
some compilers have additional options which only apply to the
"..." form, as well. And of course, the only thing the standard
really says is that if the search with the "..." form fails, the
compiler should retry as if it were specified <...>.
Is there a sort of minimal conventions programmers stick to to
be compiler-independent?

The usual convention seems to work well in practice: system
headers, and anything you assimulate to system headers, use
<...>, other headers use "...". You'll probably find some
variation as to what is assimulated to system headers, however:
some places will include not only third party libraries, like
wxWidgets, but also lower level in house libraries which are
used in many different projects, where as others may not even
consider major third party libraries, limiting <...to those
libraries furnished with the compiler or bundled with the OS.

In general, I wouldn't worry about it too much, except to ensure
that local headers use "...".

--
James Kanze (GABI Software) email:james.ka. ..@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Correct me if I am wrong. My understanding is that <...will include
the system defined path. "..." will search the user defined path where
you use -I to specify if you are using UNIX.

Nov 5 '07 #4
"we*********@gm ail.com" <we*********@gm ail.comwrote in
news:11******** **************@ z24g2000prh.goo glegroups.com:
>
Correct me if I am wrong. My understanding is that <...will include
the system defined path. "..." will search the user defined path where
you use -I to specify if you are using UNIX.
All of the compilers that I've used will apply the -I directories to both
<and "" includes.
Nov 5 '07 #5
James Kanze <ja*********@gm ail.comwrites:
I might add that when generating dependencies, g++ has an option
to only consider the files included by "..." in the generated
dependencies.
I believe that you are mistaken, for recent versions of GCC.
From the GCC 4.1 manual:

`-MM'
Like `-M' but do not mention header files that are found in system
header directories, nor header files that are included, directly
or indirectly, from such a header.

This implies that the choice of angle brackets or double quotes in
an `#include' directive does not in itself determine whether that
header will appear in `-MM' dependency output. This is a slight
change in semantics from GCC versions 3.0 and earlier.

(GCC 3.0 is 6 years old.)
--
Ben Pfaff
http://benpfaff.org
Nov 6 '07 #6
On Nov 7, 12:03 am, Ben Pfaff <b...@cs.stanfo rd.eduwrote:
James Kanze <james.ka...@gm ail.comwrites:
I might add that when generating dependencies, g++ has an option
to only consider the files included by "..." in the generated
dependencies.
I believe that you are mistaken, for recent versions of GCC.
From the GCC 4.1 manual:
`-MM'
Like `-M' but do not mention header files that are found in system
header directories, nor header files that are included, directly
or indirectly, from such a header.
This implies that the choice of angle brackets or double quotes in
an `#include' directive does not in itself determine whether that
header will appear in `-MM' dependency output. This is a slight
change in semantics from GCC versions 3.0 and earlier.
So it would seem. I was looking at two different versions of
g++ when I wrote this: the latest, but also 2.95.3 (trying to
find the option to add a directory to the path only for <...>,
which I thought was there at one time), and apparently got
confused about them.

IMHO, this is a step backwards, since it no longer allows the
project to define what it considers "system". In addition to
the standard headers, for example, we use Posix, Sybase and
Reuteurs (and maybe some other stuff I'm not aware of).
Conceptually, they're all "system" for us, and it would be
preferable not to consider them when generating dependencies.
Presumable, g++ doesn't consider the Posix headers (which are in
/usr/include), but would consider the Sybase and Reuteurs
headers (which are all somewhere under /tools in our
systems)---and if the installation installed the Sybase and
Reuteurs headers under /usr/include, g++ would act differently.
(What about /usr/local/include? I have the impression that a
lot of Linux system software installs its headers there. And a
lot of Linux non-system software installs them under
/usr/include.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 7 '07 #7

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

Similar topics

6
4656
by: JStrummer | last post by:
I have a question regarding paths and the include() statement in PHP. I develop in a Windows environment and will be publishing to a Linux server. I would like to do the following: 1. Setup my include references in such a way that I don't have to change them all every time I have to publish to the production server 2. Setup above in such a way that won't involve php.ini (& LInux equivalent), as I have access to edit this file...
5
2506
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to very carefully define the order in which paths are searched with command line options on the compiler. Both can cause problems, especially when dealing with complex software distributions. It occurs ot me that by extending the C include...
2
1500
by: Bill Roper | last post by:
Did you know that the #include directive when using angle brackets works substantially differently in VC7 than it did in VC6? It used to be that the reference for the additional include directories that you specify for the project started from the project directory. Now it appears to start from the directory that you're including the file from. So if you have a directory structure like this:
11
2258
by: MBS | last post by:
I am playing around with some PHP code. I want to put in an include() function so I can include existing HTML code and output it to the browser. Lo and behold PHP does not support relative paths with the include() function! (How shortsighted can you get?) Is there any way at all to use relative paths with include()? Any hacks? If I use an absolute filepath, everything is fine. But I don't want to do that--I can't do that. I want...
10
18887
by: Eric | last post by:
Hello, I have some server side includes on a Classic asp page that look something like: <!-- #include virtual="/includes/file1.asp"--> <!-- #include virtual="/includes/file2.asp" --> <!-- #include virtual="/includes/file3.asp" --> <!-- #include virtual="/includes/file4.asp" --> <!-- #include virtual="/includes/file5.asp" -->
111
4622
by: Nate | last post by:
Hello, I am looking for a method to automatically declare variables in C. I'm not sure if there is a good way to do this, but I had something like this in mind... int i; for(i = 1; i < 4; i++){
2
3785
by: dave6502 | last post by:
Struggling newbe here, some of my #includes work, some dont. Is it possible to list the include path ? (in BASH), I have looked at the environmental variables (loads of them) but cannot find a reference. Cheers Dave
7
4127
by: berkshire | last post by:
We recently upgraded php from 4.3.9 to 4.4.7. Everything is working well, except the php scripts running as cronjobs. It appears the problem is that these scripts utilize the include() function and these functions are utilizing relative paths. They worked just fine with the old version of php, but not with the new version. Anyone know what is causing this hiccup? TIA
12
1740
by: duzhidian | last post by:
failed to open stream: No such file or directory I have the programs like this structure: a.php is locate at . b.php is located at ./lib c.php is located at ./lib/sublib a.php uses a function at b.php while b.php using a function at c.php
0
8717
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
8498
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
8600
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
7311
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...
0
5629
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
4150
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1600
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.