On Mon, 26 Oct 2015 08:42:13 CST
Kim Walisch <
kim.w...@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