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

Discussion in 'C++' started by Victor Bazarov, Mar 5, 2005.

  1. "Exits Funnel" <> 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
     
    Victor Bazarov, Mar 5, 2005
    #1
    1. Advertising

  2. Victor Bazarov

    Exits Funnel Guest

    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
     
    Exits Funnel, Mar 5, 2005
    #2
    1. Advertising

  3. Victor Bazarov

    Jack Klein Guest

    On Sat, 5 Mar 2005 00:21:01 -0500, "Victor Bazarov"
    <> wrote in comp.lang.c++:

    > "Exits Funnel" <> 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/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Mar 6, 2005
    #3
  4. "Exits Funnel" <> 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
     
    Victor Bazarov, Mar 6, 2005
    #4
  5. Victor Bazarov

    Exits Funnel Guest

    > 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
     
    Exits Funnel, Mar 6, 2005
    #5
    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. PTM
    Replies:
    1
    Views:
    344
    Andy Dingley
    Nov 12, 2007
  2. naveeddil
    Replies:
    0
    Views:
    605
    naveeddil
    Jan 4, 2008
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    973
    Andreas Bogenberger
    Feb 22, 2008
  4. Eric
    Replies:
    10
    Views:
    488
  5. Eric
    Replies:
    0
    Views:
    271
Loading...

Share This Page