C++ include statements

Discussion in 'C++' started by Alf P. Steinbach, Aug 15, 2005.

  1. * Jacob:
    > Is there still a difference on the two forms
    > of includes:
    >
    > #include "some/file"
    >
    > and
    >
    > #include <some/file>
    >
    > I always use the latter and see no rational
    > reason to distinguish between "system" headers
    > and "enterprise" headers.


    The former allows the compiler to search in addition places, which in
    practice means the directory of the file doing the #include.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Aug 15, 2005
    #1
    1. Advertising

  2. Alf P. Steinbach

    Jacob Guest

    Is there still a difference on the two forms
    of includes:

    #include "some/file"

    and

    #include <some/file>

    I always use the latter and see no rational
    reason to distinguish between "system" headers
    and "enterprise" headers.

    Thanks!
     
    Jacob, Aug 15, 2005
    #2
    1. Advertising

  3. Jacob wrote:
    > Is there still a difference on the two forms
    > of includes:
    >
    > #include "some/file"
    >
    > and
    >
    > #include <some/file>
    >
    > I always use the latter and see no rational
    > reason to distinguish between "system" headers
    > and "enterprise" headers.


    On some compilers (gcc) automatically generated header dependantcies are
    only done with the "" style includes. Hence, any header file you expect
    to be in your source tree should use "" style includes and anything
    outside your source tree should use <> style includes.

    "" style includes will first be searched for in the same directory as
    the file being included.
     
    Gianni Mariani, Aug 15, 2005
    #3
  4. Alf P. Steinbach

    benben Guest

    > The former allows the compiler to search in addition places, which in
    > practice means the directory of the file doing the #include.


    In addition to what Alf had said, a standard header to be #included with <>
    need not be a file at all, although I haven't seen a real life example of
    so.

    ben
     
    benben, Aug 15, 2005
    #4
  5. Alf P. Steinbach

    Pete Becker Guest

    Jacob wrote:

    >
    > I'd suggest always using the <> syntax so that you don't
    > accidently find include files through mysterious (and
    > possibly compiler/platform dependent) ways.
    >


    You've obviously been hit over the head with the "non-portable" club too
    many times. There's nothing wrong with compiler/platform dependent ways
    of finding include files. If you port your code to another platform you
    deal with it. In practice, unless you're deliberately displacing headers
    you won't run into problems. Indeed, your original example of #include
    <some/file> will cause you more problems than the include paths themselves.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, Aug 15, 2005
    #5
  6. * Jacob:
    > Alf P. Steinbach wrote:
    >
    > > The former allows the compiler to search in addition places, which in
    > > practice means the directory of the file doing the #include.

    >
    > But if you depend on this fact you probably has a flaw
    > in your development environment.


    No.

    It's been this way, with good reason, since K&R C in 1972 or thereabouts.


    > I'd suggest always using the <> syntax so that you don't
    > accidently find include files through mysterious (and
    > possibly compiler/platform dependent) ways.


    First, it's not a problem.

    Second, if it were a problem, the proposed solution would not be a solution.


    > Suggestions?


    Forget all you've "learned" in your current workplace. ;-)

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Aug 15, 2005
    #6
  7. Alf P. Steinbach

    Pete Becker Guest

    Jacob wrote:
    >
    > I'd suggest always using the <> syntax so that you don't
    > accidently find include files through mysterious (and
    > possibly compiler/platform dependent) ways.
    >


    Forgot to mention: the compiler's lookup rules are mysterious only if
    you don't look 'em up. Unfortunately, there seems to be a trend among
    programmers today to program by guesses rather than knowledge.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, Aug 15, 2005
    #7
  8. Alf P. Steinbach

    Jacob Guest

    Alf P. Steinbach wrote:

    > The former allows the compiler to search in addition places, which in
    > practice means the directory of the file doing the #include.


    But if you depend on this fact you probably has a flaw
    in your development environment.

    I'd suggest always using the <> syntax so that you don't
    accidently find include files through mysterious (and
    possibly compiler/platform dependent) ways.

    Suggestions?
     
    Jacob, Aug 15, 2005
    #8
  9. Alf P. Steinbach

    Default User Guest

    Jacob wrote:

    > Alf P. Steinbach wrote:
    >
    > > The former allows the compiler to search in addition places, which
    > > in practice means the directory of the file doing the #include.

    >
    > But if you depend on this fact you probably has a flaw
    > in your development environment.
    >
    > I'd suggest always using the <> syntax so that you don't
    > accidently find include files through mysterious (and
    > possibly compiler/platform dependent) ways.




    Our common coding standard mandates that user-defined headers be
    enclosed in "" and system (not-necessarily standard) ones in <>.

    That make sense to me, because that way the maintainer knows whether
    the header should be in the code tree or if it's found somewhere else.



    Brian
     
    Default User, Aug 15, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    8
    Views:
    1,190
    mfmehdi
    Oct 20, 2006
  2. Harry George
    Replies:
    6
    Views:
    377
    Bart Nessux
    Feb 23, 2004
  3. Vince
    Replies:
    12
    Views:
    749
    Martin Gregorie
    Jan 21, 2008
  4. Andreas Bogenberger
    Replies:
    3
    Views:
    925
    Andreas Bogenberger
    Feb 22, 2008
  5. John Crichton
    Replies:
    6
    Views:
    264
    John Crichton
    Jul 12, 2010
Loading...

Share This Page