#include directive
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: #include directive

  1. #1
    Join Date
    Dec 2003
    Posts
    99

    #include directive

    What is the difference between the following to statements:

    1. #include <abc.h>

    2. #include "abc.h"

    Regards

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,471
    Hi!
    According to MSDN The #include Directive :
    ....
    #include "path-spec"

    #include <path-spec>

    The path-spec is a filename optionally preceded by a directory specification. The filename must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled.

    Both syntax forms cause replacement of that directive by the entire contents of the specified include file. The difference between the two forms is the order in which the preprocessor searches for header files when the path is incompletely specified.

    Syntax Form Action
    Quoted form This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of whatever files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.
    Angle-bracket form This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then along the path specified by the INCLUDE environment variable.


    The preprocessor stops searching as soon as it finds a file with the given name. If you specify a complete, unambiguous path specification for the include file between two sets of double quotation marks (" "), the preprocessor searches only that path specification and ignores the standard directories.
    ....

  3. #3
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,471
    According to the ISO standard (section 16.2),
    2 A preprocessing directive of the form

    # include <hcharsequence> newline

    searches a sequence of implementation defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.

    3 A preprocessing directive of the form

    # include "qcharsequence" newline

    causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

    # include <hcharsequence> newline

    with the identical contained sequence (including > characters, if any) from the original directive.
    In other words, the quoted form should always find a header that the <> form would, but not the other way around.

    In practice, use the <> form for system headers and the quoted form for application-specific headers.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  4. #4
    Join Date
    Dec 2003
    Posts
    99
    In other words, the quoted form should always find a header that the <> form would, but not the other way around.

    In practice, use the <> form for system headers and the quoted form for application-specific headers.
    Thanks all,
    I am using a library in my project. When I build it in debug mode it builds fine. But when in Releease mode the header files are not found!!! If i give absolute path it works.
    The "include directories" for both the configurations is the same.

    The problem is solved by replacing #include "lib.h" by #include <lib.h>?

    The library is a third-party thing I only have the headers.

    Regards

  5. #5
    Join Date
    Dec 2003
    Location
    Montreal
    Posts
    58
    Because the search is implementation defined, you will need to consult the compiler's documentation to see how it implements each format.

    If it works in debug but not release, you have different settings for each so when you change one, it is not reflected in the other unles you did so specifically, update the release settings.

    Make sure your include path is the same for both debug and release. As a good rule of thumb, use the <> format when the header file is not contained within you project's directory structure, and use the "" format when it is.

  6. #6
    Join Date
    Dec 2003
    Posts
    99
    Thanks

    Make sure your include path is the same for both debug and release. As a good rule of thumb, use the <> format when the header file is not contained within you project's directory structure, and use the "" format when it is.
    As I said "include directories" for both the configs is the same
    Any other parameter that I should check.

    Though the search method or sequence is different both must always search include directories right ?

    Regards
    Last edited by nsh123; January 13th, 2004 at 01:59 AM.

  7. #7
    Join Date
    Sep 2002
    Posts
    1,747
    Often, the include directory is set per build type. Maybe you just haven't set your include directory properly for relase build?
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center