Nested Header Files in C

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:
550
1
Yes, that is allowed and it should work.
 

mgb_phys

Science Advisor
Homework Helper
7,660
11
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
 

The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top