Thread: typedef issue

  1. #16
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    A #include is equivalent to literally copying and pasting the entire header file into wherever it is included into.
    So if you have foo.cpp which includes foo.h and bar.h, and bar.h also includes foo.h, then the resulting source file is compiled with the contents of foo.h pasted into it twice.

    The include guards just tell the compiler to ignore any subsequent copies of that header within the resulting source file being compiled. It still copies it in there twice, but the second occurrence is ignored. Some compilers allow you to use "#pragma once" at the top of the file which actually stops the second and subsequent inclusions of the header, but it's not supported on all compilers.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #17
    Registered User
    Join Date
    May 2011
    Posts
    116
    Quote Originally Posted by iMalc View Post
    A #include is equivalent to literally copying and pasting the entire header file into wherever it is included into.
    So if you have foo.cpp which includes foo.h and bar.h, and bar.h also includes foo.h, then the resulting source file is compiled with the contents of foo.h pasted into it twice.

    The include guards just tell the compiler to ignore any subsequent copies of that header within the resulting source file being compiled. It still copies it in there twice, but the second occurrence is ignored. Some compilers allow you to use "#pragma once" at the top of the file which actually stops the second and subsequent inclusions of the header, but it's not supported on all compilers.
    thanks for the explanation

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. typedef issue
    By Drac in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2009, 04:41 PM
  3. typedef help
    By switchcase in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2007, 12:21 PM
  4. typedef
    By abhi_86 in forum C Programming
    Replies: 26
    Last Post: 04-11-2007, 03:20 PM
  5. ? about typedef
    By smd in forum C++ Programming
    Replies: 8
    Last Post: 07-23-2003, 10:49 AM