header files

This is a discussion on header files within the C++ Programming forums, part of the General Programming Boards category; When including ".h" (header files) into a program, does the file have to be in a relative directory to the ...

  1. #1
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67

    Question header files

    When including ".h" (header files) into a program, does the file have to be in a relative directory to the file that is calling it? And if so, what is the difference from using "somefile.h" to <somefile>?

    thanks.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    <somefile.h> includes from the compiler include directories.
    "somefile.h" includes from the relative directory to the file that is calling it.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    <somefile.h> includes from the compiler include directories.
    "somefile.h" includes from the relative directory to the file that is calling it.
    Not necessary. In the project you can specify several include directories that compiler will search for include files... It's a good practice to distinct standard includes from project file includes using <> and "" syntax

    Update
    Here is what msdn says:
    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 any 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, when compiling from the command line, along the path specified by the INCLUDE environment variable.
    Last edited by vart; 10-28-2006 at 12:01 PM.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And here's what the standard says:
    Code:
    2 A preprocessing directive of the form
              # include <h-char-sequence> new-line
      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 "q-char-sequence" new-line
      causes the replacement of that directive by the entire contents of the
      source  file identified by the specified sequence between the " delim-
      iters.  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 <h-char-sequence> new-line
      with the identical contained sequence (including > characters, if any)
      from the original directive.
    In other words, nothing much. In theory, every compiler is free to do whatever it wants, as long as it documents it.

    MS's documentation pretty much is the established convention, except that it is redundant: the quoted form could omit the part about /I and INCLUDE, because the standard says that if the method of the quoted form fails, the method of the angle-bracket form must be tried.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21