Hello,
I have a question. I read that C header files can be incluided more than once, with the effect being the same as if they were included only once, is that correct? Now why would anyone want to be redundant? Thats my ?
![]()
This is a discussion on C header file question? within the C Programming forums, part of the General Programming Boards category; Hello, I have a question. I read that C header files can be incluided more than once, with the effect ...
Hello,
I have a question. I read that C header files can be incluided more than once, with the effect being the same as if they were included only once, is that correct? Now why would anyone want to be redundant? Thats my ?
![]()
to make a C header file so that it can be #include'd more than once but will only be #include'd once, do something like this
foobar.h:
why? because header files sometimes include other header files, for various reasons, and especially when you get into a large many filed program, this method stops "circular dependancies" from occurning whereCode:#ifndef FOOBAR_HEADER_FILE #define FOOBAR_HEADER_FILE // put your header code here, then right before the end of file: #endif
foo.h includes bar.h
bar.h includes kensmom.h
kensmom.h includes foo.h
with this (very standard btw) method,
foo.h includes bar.h
bar.h includes kensmom.h
kensmom.h says to include foo.h, but the preprocessor looks and see's that foo.h has already been included, so it doesnt include it again.
hello, internet!
oh!
Thanks, i'll remember that.
![]()
It takes less effort to slap it in, whether it's needed or not. That's why they sometimes get included more than once.