Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Nested Header Files in C

  1. Feb 17, 2009 #1
    I was wondering if nested header files are achievable in C? I tried placing #include "header.h" inside a header file but I don't think it worked. thanks.
     
    Last edited: Feb 17, 2009
  2. jcsd
  3. Feb 17, 2009 #2
    Yes, that is allowed and it should work.
     
  4. Feb 17, 2009 #3

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    It does work, although it should be reduced as much as possible.
    It's confusing and leads to long compile times.

    To avoid problems of a header being included twice in a . cfile through differnet routes you should put include guards around it.
    Code (Text):

    #ifndef NAME_OF_HEADER_H
    #define NAME_OF_HEADER_H

    .... rest of header file

    #endif
     
    or if your compiler supports it, just put "#pragma once" at the top of the file
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Nested Header Files in C
Loading...