f



Include precedence <> vs "" for system libraries (Unix-like OSes)

Many system libraries offer a main header file in the root directory
e.g. /usr/include which then includes a few other headers located
inside a directory also installed in /usr/include. Below are a few
examples from my Linux box:

/usr/include/ruby.h
/usr/include/ruby

/usr/include/krb5.h
/usr/include/krb5

/usr/include/lzma.h
/usr/include/lzma

/usr/include/gssapi.h
/usr/include/gssapi

Now if you look inside the headers above some include their other
headers using <> while others use "", e.g.:

cat /usr/include/gssapi.h | grep include
#include <gssapi/gssapi.h>

cat /usr/include/ruby.h | grep include
#include "ruby/ruby.h"

The second version using "" seems more correct to me. I wonder if using
<> might potentially cause issues when 2 versions of the library are
installed e.g. one in /usr/include and another in /usr/local/include (
will the header inside /usr/include reference its other headers inside
/usr/local/include instead of /usr/include?).

So my question is: Are both (<> & "") uses safe or should one be
preferred over the other?

Thanks,
Kim


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Kim
10/26/2015 8:42:13 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

4 Replies
328 Views

Similar Articles

[PageSpeed] 47

On Monday, October 26, 2015 at 6:50:16 AM UTC-7, Kim Walisch wrote:
> Many system libraries offer a main header file in the root directory
> e.g. /usr/include which then includes a few other headers located
> inside a directory also installed in /usr/include. Below are a few
> examples from my Linux box:
> 
> /usr/include/ruby.h
> /usr/include/ruby
> 
> /usr/include/krb5.h
> /usr/include/krb5
> 
> /usr/include/lzma.h
> /usr/include/lzma
> 
> /usr/include/gssapi.h
> /usr/include/gssapi
> 
> Now if you look inside the headers above some include their other
> headers using <> while others use "", e.g.:
> 
> cat /usr/include/gssapi.h | grep include
> #include <gssapi/gssapi.h>
> 
> cat /usr/include/ruby.h | grep include
> #include "ruby/ruby.h"
> 
> The second version using "" seems more correct to me. I wonder if using
> <> might potentially cause issues when 2 versions of the library are
> installed e.g. one in /usr/include and another in /usr/local/include (
> will the header inside /usr/include reference its other headers inside
> /usr/local/include instead of /usr/include?).
> 
> So my question is: Are both (<> & "") uses safe or should one be
> preferred over the other?
> 

The only difference between the two is that when using "" the compiler will
first look for the include file in the local directory in which the
compilation command is executed, then if it is not found will continue to
search in the system-dependent standard include path (except, of course,
this is all after searching in any directories named with -I flags on the
command line)


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
FredK
10/26/2015 11:30:16 AM
On 10/26/2015 10:42 AM, Kim Walisch wrote:
> 
> Many system libraries offer a main header file in the root directory
> e.g. /usr/include which then includes a few other headers located
> inside a directory also installed in /usr/include. Below are a few
> examples from my Linux box:
> 
> /usr/include/ruby.h
> /usr/include/ruby
> 
> /usr/include/krb5.h
> /usr/include/krb5
> 
> /usr/include/lzma.h
> /usr/include/lzma
> 
> /usr/include/gssapi.h
> /usr/include/gssapi

Keep in mind that not a single one of those files is a C++ standard
library header. Also keep in mind that the actual locations of those
files can vary from one computer to another, even on Unix-like systems,
to say nothing of other operating systems.

> Now if you look inside the headers above some include their other
> headers using <> while others use "", e.g.:
> 
> cat /usr/include/gssapi.h | grep include
> #include <gssapi/gssapi.h>
> 
> cat /usr/include/ruby.h | grep include
> #include "ruby/ruby.h"
> 
> The second version using "" seems more correct to me. I wonder if using
> <> might potentially cause issues when 2 versions of the library are
> installed e.g. one in /usr/include and another in /usr/local/include (
> will the header inside /usr/include reference its other headers inside
> /usr/local/include instead of /usr/include?).
> 
> So my question is: Are both (<> & "") uses safe or should one be
> preferred over the other?

The only thing required by the C++ standard is that there be an
implementation-defined list of locations that is searched when using
#include <file.h>, and a possibly different implementation-defined set
of locations that is searched when you use #include "file.h". The only
standard distinction between them is that if you use #include "file.h",
and the search fails, it then retries the search exactly as if you had
used #include <file.h>. Thus, #include <file.h> is a more tightly
constrained search than #include "file.h".

What this means depends upon how the implementation chooses to define
the search locations. But as a rule, I think you should use #include <>
only for C standard headers and operating-system headers, and #include
"" for all others. This is just my opinion - the standard says nothing
about that issue.
-- 
James Kuyper


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
James
10/26/2015 3:39:42 PM
On Monday, October 26, 2015 at 8:40:22 PM UTC, James Kuyper wrote:
> > So my question is: Are both (<> & "") uses safe or should one be
> > preferred over the other?

James sums it up very well:-

> The only thing required by the C++ standard is that there be an
> implementation-defined list of locations that is searched when using
> #include <file.h>, and a possibly different implementation-defined set
> of locations that is searched when you use #include "file.h". The only
> standard distinction between them is that if you use #include "file.h",
> and the search fails, it then retries the search exactly as if you had
> used #include <file.h>. Thus, #include <file.h> is a more tightly
> constrained search than #include "file.h".
> 
> What this means depends upon how the implementation chooses to define
> the search locations.
[snip]
> -- 
> James Kuyper

I think the upshot of this is that it is yet another style issue, like tabs
versus spaces or the one true brace style. You can't say that one way is
better than another, only what the house style is. I have seen people argue
over which style is inherently superior to no avail. I must confess, I have
even started such arguments myself in the past. But I don't bother any more.
I just stick with the house style, whatever that is.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
marlow
11/4/2015 6:56:05 AM
On Mon, 26 Oct 2015 08:42:13 CST
Kim Walisch <kim.walisch@googlemail.com> wrote:

> cat /usr/include/gssapi.h | grep include
> #include <gssapi/gssapi.h>
> 
> cat /usr/include/ruby.h | grep include
> #include "ruby/ruby.h"
> 
> The second version using "" seems more correct to me.
.....
> So my question is: Are both (<> & "") uses safe or should one be
> preferred over the other?

The use of <> is better.  Using "" invites error, although you have to
work at it.  

Traditionally the difference between <> and "" is whether or not the
current working directory of the compiler process is searched before
the regular search path is consulted.  I can't find it documented in 
cpp(1) for GNU, but that is (among other things) what happens.  (While
cpp isn't used by c++, your question still holds for C if the files
could be used by a C compiler.)  

I don't have ruby installed, but I can fake out my compiler: 

$ cat ruby/ruby.h 
#define ONE 1

$ printf '#include <ruby/ruby.h>\n' | cpp -dD | tail -3 
<stdin>:1:23: fatal error: ruby/ruby.h: No such file or directory 
compilation terminated.
.....

$ printf '#include "ruby/ruby.h"\n' | cpp -dD | tail -3
# 1 "ruby/ruby.h" 1
#define ONE 1
# 1 "<stdin>" 2

If your project has a "ruby" directory, you can't have a file
"ruby/ruby.h" because ruby's own header file will read that file
instead of the intended one.  If /usr/include/ruby.h had used <>
instead of "", your project directory would be excluded from the search
path.  That is, your file could have both lines

	#include <ruby.h>
	#include "ruby/ruby.h"

with no conflict or ambiguity.  

The usual use of "" is for include files that are specific to a project
and will never be installed to a standard location.  On rare occasions,
"" might be used to override a standard include file, but I don't
remember the last time I did that.  Nowadays the preprocessor/compiler
has many better command-line options for expressing the search path.  

--jkl


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
James
11/4/2015 6:56:38 AM
Reply:

Similar Artilces:

Hello "<<<<<<<<<<<<<" HELP ME PLEASE ">>>>>>>>>>>>>>>>>>>>>>>"!!!!!!!!!!!!
Please Help me Quickly :------------------- Generate a 100x100 pixel images with the following colors and show a figure for each of them. Colors requested: Green, Cyan, "RERE " <randalfa@yahoo.com> wrote in message <ic33ck$7cm$1@fred.mathworks.com>... > Please Help me Quickly :------------------- > Generate a 100x100 pixel images with the following colors and show a figure for each of them. Colors requested: Green, Cyan, YESSIR! We will drop everything and do your homework for you. Right now however, the backlog is up to 7 weeks before we can start yo...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>jsSHA
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en"> <head> <title>jsSHA (http://jssha.sourceforge.net/) - Test</title> <script type=3D"text/javascript" src=3D"../src/sha.js"></script> <meta http-equiv=3D"Content-Type" content=3D"text/html;charset=3Dutf-8" /= > <style type=3D"text/css"> label { width: 235px; dis...

"new" [<TypeArguments>] <ClassOrInterfaceType> "(" [<ArgumentList>] ")"
According to http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.9 the following production holds <ClassInstanceCreationExpression> ::= "new" [<TypeArguments>] <ClassOrInterfaceType> "(" [<ArgumentList>] ")" What would be an example for a class instance creation expression with type arguments? Here's a reminder about those: <TypeArguments> ::= "<" <TypeArgument> {"," <TypeArgument>} ">" What I would understand would be: <ClassInstanceCre...

<a href="file://C:\temp" target="_blank">C:\temp</a> does not work in IE anymore !
Hi, in our webpage, a user could open a windows explorer to his temp directory with a simple link and usage of the file protocol: <a href="file://C:\temp" target="_blank">C:\temp</a> This worked very well a long time, but now it does not work anymore. We use IE6 and Microsoft Windows XP Professional 2002 SP2. I guess it has something to do with new IE security features. Does anybody know a workaround or how we can disable this IE behaviour. Thanks Dieter Dieter Salath? said the following on 11/22/04 13:51: > in our webpage, a user could ...

"between" vs. ">= and <="
Hi, a client of us requested to replace ">= and <=" with "between" with a TIMESTAMP column. Unfortunately I am still waiting for his justification... In the meantime I thought I do some researching. Personally I cannot think of any reason why one or the other should be more efficient. I did some simplistic testing but no difference visible. (Experimental code at end.) I even believe that I once had found a statement saying that there is no difference performance wise. Any pointers? Kind regards robert SQL> show release release 1002000400 SQL> set echo ...

generics Object.getClass clarification. "<?>" vs "<? extends Object>"
Hi, First, it seems to me that <T> is completely redundant with <T extends Object>. Indeed I can cast without warning List<T> and List<T extends Object> in both way Could someone confirm? Is that specifically said in the spec? Is that really really equivalent? Second, for the same reason, I also think that <?> is equivalent to <? extends Object>. Could someone confirm? Third, the signature of the method Object.getClass() is: Class<? extends Object> getClass(). Why they didn't write the following simple simple instead: Class<?> getClass()....

[News] "Linux" vs "Operating System <X>" Comparison is Flawed
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Linux and the PC Mentaility ,----[ Quote ] | Here’s a minor thought dump of the moment: no hard numbers, just some general | observations over the past year or two. | | I’ve heard the comparison between Linux and other UNIX like OSes a few times | in the past. Of course it is a bit hard to compare “Linux” - which is a | kernel - and the others which most often are complete operating systems. | Many times they even share a lot of GNU userland tools, so I will disregard | userland. `---- http://www.kev009.com/wp/2008/12/linux-and-the-...

#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 th...

"a < b < c" not the same as "(a < b) && (b < c)"?
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and c? e.g: for a = 0, b = 3 and c = 2: a < b < c = 1 (a < b) && (b < c) = 0 when typed in C. "Paminu" <jadajada@asd.com> wrote in message news:diisn6$8df$1@news.net.uni-c.dk... > In math this expression: > > (a < b) && (b < c) > > would be described as: > > a < b < c > > But why is it that in C...

my own perl "dos->unix"/"unix->dos"
i made a dos to unix, unix to dos program catered for my own purposes. it's seems to work fine. small program, 26 lines anyone see any potential problems with it? do you have a better way to do it? my next step is to slip in some code to automatically "detect" whether its a unix or dos file. #!/usr/bin/perl -w use strict; #setting based on filename argument. # if sym link is dos-unix or if sym link is unix-dos my ($from, $to); my $option=substr($0,rindex($0,'/')+1,length($0)-1); # $0 gives full path. this code gives just filename if ($option eq "dos-unix"){ ...

compound statement from C "<test>?<true-val>:<false-val>"
Hi I have not been able to figure out how to do compound statement from C - "<test>?<true-val>:<false-val>" But something similar must exist...?! I would like to do the equivalent if python of the C line: printf("I saw %d car%s\n", n, n != 1 ? "s" : "") Please help /Holger http://effbot.org/pyfaq/is-there-an-equivalent-of-c-s-ternary-operator.htm -- EduardoOPadoan (eopadoan->altavix::com) Bookmarks: http://del.icio.us/edcrypt Blog: http://edcrypt.blogspot.com Jabber: edcrypt at jabber dot org ICQ: 161480283 GTalk: eduardo do...

can I overload operators like "=>", "->" or something like that?
hi all, can I somehow overload operators like "=>", "->" or something like that? (I'm searching for appropriate overload for logical implication "if a then b") Thank you in advance, D. On Thursday, April 19, 2012 12:28:50 PM UTC-7, dmitrey wrote: > hi all, > can I somehow overload operators like "=>", "->" or something like > that? (I'm searching for appropriate overload for logical implication > "if a then b") > Thank you in advance, D. I don't believe that you could overload those particular ...

<<<<< URGENT
In matlab, by comparing these two, are they samething? %%%%%%%%%%%%%%%%%%%%%%%%% function grav = gravity global x y z grav = x+y+z; %%%%%%%%%%%%%%%%%%%%%%%%% and %%%%%%%%%%%%%%%%%%%%%%%%% function gravity global x y z grav = x+y+z; %%%%%%%%%%%%%%%%%%%%%%%%% Thank you Look carefully at them and tell us what you think. Dan On Sat, 03 Apr 2004 02:46:52 +0000, Ysjung wrote: > In matlab, > by comparing these two, are they samething? > > %%%%%%%%%%%%%%%%%%%%%%%%% > function grav = gravity > > global x y z > > grav = x+y+z; > %%%%%%%%%%%%%%%%%%%%%%%%% ...

C"Future library directions" names in C++ <xxx.h> headers
Are the names specified as reserved in "Future library directions" of the C standard also reserved in C++? As an example, in C++, is it proper for the ideal implementation to declare isblank() in the global namespace when <ctype.h> is included? Aaron W. LaFramboise --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ] ...

Web resources about - Include precedence <> vs "" for system libraries (Unix-like OSes) - comp.lang.c++.moderated

Resources last updated: 1/25/2016 2:11:57 AM