a word on preprocessor directives

This is a discussion on a word on preprocessor directives within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I was typing out some code when a question popped up in my head that I was dying ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    a word on preprocessor directives

    Hey everyone,
    I was typing out some code when a question popped up in my head that I was dying to have the answer to. Here goes: why is it that when you #include a header file of your own creation (what's the correct terminology? Send a header file to #include?) you write out code like the following:
    Code:
    #include "whatever.h"
    but when dealing with files that come with your compiler like iostream, you write:
    Code:
    #include <iostream>
    What exactly is the necessity for the difference in syntax...why arent you able do the following:
    Code:
    #include <whatever>
    or
    Code:
    #include "iostream.h"
    Just call this intense curiosity, any insight into this question would be more than appreciated. Thanks a lot-Chap

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > #include "whatever.h"
    Use this when you're including a file which is closely related (in the same directory) as the source file. foo.cpp would typically #include "foo.h".

    > #include <whatever.h>
    There are 2 cases
    1. You've written a library you want to make use of in multiple projects
    2. You've downloaded a library you want to make use of in your projects.
    The <> tells the preprocessor to search all the standard include directories for the file. In most cases, extra files are not in the standard places, so you have to tell it where else to look.
    In gcc, you would use
    Code:
    gcc -I/path/to/otherlib -I/path/to/mylib foo.cpp
    People using IDE's should look at the project settings, and edit the "additional include directories" field.

    > #include <whatever>
    Is the same as the previous example when it comes to locating the file.
    It may be that files without a .h imply that namespaces are being used, but that's only a guess on my part.
    Certainly any well-written C++ library would use namespaces of some sort or another.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 05:44 PM

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