473,511 Members | 12,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#include "file" -vs- #include <file>

Hello,

I'm slightly confused about when to use parens around #included files
and when to use angle brackets. I understand (I think) that the
difference is that the compiler will search in its standard include
directories for files included as <file> but not for those included as
"file". It's clear to me then that headers for the standard libraries
(eg, iostream) should be included using the '#include <iostream>' form
while header files for the classes I write should be included as
'#include "myheader.h"'.

I'm not so sure though for the cases in between. For example what if I
purchase a third party library. Which form should I use to include its
headers? Are there any hard and fast rules? Any conventions? Thanks
in advance for any replies.

-exits

Jul 23 '05 #1
4 15034
"Exits Funnel" <ex*********@noyahoospam.com> wrote...
I'm slightly confused about when to use parens around #included files
You're not alone.
and when to use angle brackets. I understand (I think) that the
difference is that the compiler will search in its standard include
directories for files included as <file> but not for those included as
"file". It's clear to me then that headers for the standard libraries
(eg, iostream) should be included using the '#include <iostream>' form
while header files for the classes I write should be included as '#include
"myheader.h"'.
Both forms cause implementation-defined behaviour. Whatever you know
about what actually happens is specific to your compiler. Another
compiler is free to behave differently. It has to document it, however.
I'm not so sure though for the cases in between. For example what if I
purchase a third party library. Which form should I use to include its
headers? Are there any hard and fast rules? Any conventions? Thanks in
advance for any replies.


It's all driven by the compiler rules. Read the documentation for your
compiler, it should explain those details. Most compilers I used did
have <> for searching in "predefined places", but VC++, for example, will
search for "" in those places, too.

Recently I've read some things about the differences, alleging that <>
(angle brackets) are reserved for the compiler headers. AFAICT it's not
necessarily so, and even if it is so in the Standard, all compilers I've
used do allow you to have your own header [file] and define its name in
the angle brackets. To me that means there is no rule saying that <>
should only name headers and never user's files.

V
Jul 23 '05 #2
On Sat, 5 Mar 2005 00:21:01 -0500, "Victor Bazarov"
<v.********@comAcast.net> wrote in comp.lang.c++:
"Exits Funnel" <ex*********@noyahoospam.com> wrote...
I'm slightly confused about when to use parens around #included files


You're not alone.
and when to use angle brackets. I understand (I think) that the
difference is that the compiler will search in its standard include
directories for files included as <file> but not for those included as
"file". It's clear to me then that headers for the standard libraries
(eg, iostream) should be included using the '#include <iostream>' form
while header files for the classes I write should be included as '#include
"myheader.h"'.


Both forms cause implementation-defined behaviour. Whatever you know
about what actually happens is specific to your compiler. Another
compiler is free to behave differently. It has to document it, however.
I'm not so sure though for the cases in between. For example what if I
purchase a third party library. Which form should I use to include its
headers? Are there any hard and fast rules? Any conventions? Thanks in
advance for any replies.


It's all driven by the compiler rules. Read the documentation for your
compiler, it should explain those details. Most compilers I used did
have <> for searching in "predefined places", but VC++, for example, will
search for "" in those places, too.

Recently I've read some things about the differences, alleging that <>
(angle brackets) are reserved for the compiler headers. AFAICT it's not
necessarily so, and even if it is so in the Standard, all compilers I've
used do allow you to have your own header [file] and define its name in
the angle brackets. To me that means there is no rule saying that <>
should only name headers and never user's files.

V


For the standard headers provided as part of the standard language,
such as <iostream> or <cstdlib>, the standard requires the use of <>,
and does not require that the standard headers be files.

This does not have much practical effect in any implementation that I
know of, but even if <iostream> is a file, these two directives are
not guaranteed or required to work the same way:

#include <iostream>
#include "iostream"

The second is not guaranteed to work properly by the standard, the
first is.

For inclusion of files, there is no real difference other than the
locations searched.

For a #include "somename" directive, the C++ standard requires that if
the file is not found in the special locations searched for this form
of the directive, the implementation must then search in whatever
other places it searches for the <> form of the include directive.

The real problem with putting standard headers in the "quoted" form is
that the compiler might stumble over some other file of the same name
somewhere in its search path before it comes to the real standard
header.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #3
> A lot of useful information snipped

Jack, Victor, thanks for taking the time to reply.

You've confirmed my understanding of the issue, but the question still
remains: which form do you use for 3rd party non-system headers? I
understand I can make it work with either form in conjuction with the
appropriate compiler switches but what is the standard usage? In other
words, should one use the quotes for his own files and angle brackets
for everything else or should he use angle brackets for system headers
and quotes for everything else?

Thanks again for taking the time to reply.

-exits

Jul 23 '05 #4
"Exits Funnel" <ex*********@noyahoospam.com> wrote...
A lot of useful information snipped
Jack, Victor, thanks for taking the time to reply.

You've confirmed my understanding of the issue, but the question still
remains: which form do you use for 3rd party non-system headers? I
understand I can make it work with either form in conjuction with the
appropriate compiler switches but what is the standard usage?


There is no standard usage. The Standard leaves it to the implementation.
So, for every implementation you have to make the decision about what form
to use and what compiler switches to apply.
In other words, should one use the quotes for his own files and angle
brackets for everything else or should he use angle brackets for system
headers and quotes for everything else?


Up to you. The angle brackets are required for the standard headers.
Everything else is up to the implementation.

V
Jul 23 '05 #5

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

Similar topics

35
2010
by: Will Stuyvesant | last post by:
Here is a question about list comprehensions . The question is dumb because I can do without ; but I am posing the question because I am curious. This: >>> data = ,,] >>> result = >>> for...
4
6041
by: Francesco | last post by:
Hi, I've a question... is it possible to change the default separator in the stream operator ">>" (for example from the blank space " " to the comma "," ) ? Here is an example... I want to...
1
22695
by: Krusty276 | last post by:
I'm getting this error using sql plus Input is too long (> 2499 characters) - line ignored This is my command line on linux: /home/oracle/product/8.1.6/bin/sqlplus -s loader/loader@ecrmdb...
32
2653
by: Indrid Colt | last post by:
Thank's for your help ! Indrid
1
2123
by: Charlie | last post by:
Hi: I'm using the HTML File Field control as a file picker for uploading files to a SQl Server image field. When page posts back to initiate upload, if file is small (under about two megs) all...
11
2882
by: icanoop | last post by:
I would like to do this MyClass x; istringstream("XXX") >> x; // Works in VC++ but not GCC instead of MyClass x; istringstream iss("XXX"); iss >> x; // Works in both GCC and VC++
0
1633
by: Michael Fay in SB | last post by:
I built my application with Access 2003 and made a distribution using the Microsoft Office Access 2003 Developer Extensions. (I also install Jet 8 as a follow-on action at the end of the...
3
2180
by: Pappy | last post by:
SHORT VERSION: Python File B changes sys.stdout to a file so all 'prints' are written to the file. Python file A launches python file B with os.popen("./B 2>&^1 >dev/null &"). Python B's output...
11
8302
by: jjw92 | last post by:
I've been banging my head against the wall with this one for a couple days so I'm hoping someone has some ideas. I have a web service that I created that is called by a .NET class library (which in...
3
4285
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
0
7245
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
7144
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
7356
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,...
0
7427
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
5671
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,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4741
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...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.