Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Include header files in quotes or less-than greater-than signs? (http://www.velocityreviews.com/forums/t717892-include-header-files-in-quotes-or-less-than-greater-than-signs.html)

Dwight Army of Champions 03-16-2010 02:27 PM

Include header files in quotes or less-than greater-than signs?
 
What is the difference to including .h files in quotes and in less-
than greater-than signs? Also sometimes I see the ".h" portion
included and sometimes I don't (example: #include <vector>). What's
the difference?

Marcel Müller 03-16-2010 06:19 PM

Re: Include header files in quotes or less-than greater-than signs?
 
Dwight Army of Champions wrote:
> What is the difference to including .h files in quotes and in less-
> than greater-than signs? Also sometimes I see the ".h" portion
> included and sometimes I don't (example: #include <vector>). What's
> the difference?


- <> searches the include directories
- "" searches the current directory
- Some compilers ignore that.


Marcel

Robert Fendt 03-16-2010 07:34 PM

Re: Include header files in quotes or less-than greater-than signs?
 
And thus spake Marcel Müller <news.5.maazl@spamgourmet.org>
Tue, 16 Mar 2010 19:19:51 +0100:

> - <> searches the include directories
> - "" searches the current directory
> - Some compilers ignore that.


If I recall correctly "" falls back to <> if it does not find
anything (at least I think I read something like that in the
standard somewhere).

The traditional include syntax distinction is part of C++'s C
heritage, and apart from that it can help improve readability as
well.

Regards,
Robert


James Kanze 03-16-2010 10:44 PM

Re: Include header files in quotes or less-than greater-than signs?
 
On Mar 16, 2:27 pm, Dwight Army of Champions
<dwightarmyofchampi...@hotmail.com> wrote:
> What is the difference to including .h files in quotes and in
> less- than greater-than signs? Also sometimes I see the ".h"
> portion included and sometimes I don't (example: #include
> <vector>). What's the difference?


In all cases, it's implementation defined. For the first,
almost all compilers will first look for the included file in
the directory which contains the file doing the include, then
continue as if you'd used <...>, e.i. looking in the directories
given with the -I or /I options, then in a number of fixed
locations. For the second, how the compiler maps the string
given in the include directive is implementation defined, but I
don't know of a single implementation today which doesn't treat
it literally: <vector> and <vector.h> designate two different
files.

--
James Kanze

John H. 03-17-2010 06:39 PM

Re: Include header files in quotes or less-than greater-than signs?
 
On Mar 16, 9:27*am, Dwight Army of Champions
<dwightarmyofchampi...@hotmail.com> wrote:
> Also sometimes I see the ".h" portion
> included and sometimes I don't (example: #include <vector>). What's
> the difference?


The difference is just the naming convention. Another one you might
find is ".hpp". Under the hood they are all the same thing, headers.
Most likely they are the name of header files sitting on your machine
somewhere.

The C standard library has a lot of header files ending in .h, e.g.
<stdlib.h>. When early C++ compilers incorporated the C standard
library, the easiest thing to do was to keep the same naming
conventions. So in a C program you would #include <stdlib.h>, and in
a C++ program you would #include <stdlib.h> to do the same thing.
Some features that were not part of C were also added to C++, such as
vectors, and early compilers might have used <vector.h> or <vector>.

When C++ was standardized, they decided to put the functionality of
<stdlib.h> into what C++ called <cstdlib>, similarly <assert.h> became
<cassert>, etc. The library features that were new with C++ were also
standardized, with header names that lacked the .h (e.g. <vector>,
<fstream>, etc). In addition, the functionality of the standard
library via these headers was mostly put into the namespace std.
Finally, support for the old C style headers (<stdlib.h>) was kept.

As it happens, adoption of the standardized header naming and
namespace placement by different compilers happened at different times
and sometimes incrementally between releases of a compiler. Some
compilers just know about the C name <stdlib.h>, some will offer both
C and C++ name (stdlib.h or cstdlib). In addition, some compilers put
the contents of into the std namespace, where some did not. In
recognition of this problem, in C++0x, they are specifying that it is
up the implementation if they put the function in just the std
namespace or both the std and global namespace.

So when reading code that uses functionality from the C library, you
might see either the C style name (e.g. <math.h>) or the C++ style
name (<cmath>). In addition, it may or may not be using the std
namespace. When writing code, it is probably best to use the C++
style name and assume that things are in the std namespace.

Another little thing, C and C++ have distinct string concepts. The C
style name for the C string concept is <string.h>. The C++ style name
for the C string is <cstring>. The C++ name for the C++ string is
<string> (there is no C style name for the C++ string).


All times are GMT. The time now is 08:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.