Are Nested Header Files Possible in C?

  • Thread starter Thread starter aostraff
  • Start date Start date
  • Tags Tags
    files
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 8K views
aostraff
Messages
48
Reaction score
0
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:
Physics news on Phys.org
Yes, that is allowed and it should work.
 
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:
#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