You are not logged in.
Pages: 1
Hi @ll,
Let's say I have 2 header files, each including "custom.h" which are themselfs included in main.cpp:
header1.h:
#ifndef HEADER1_H
#define HEADER1_H
#include "custom.h"
...
#endif
header2.h:
#ifndef HEADER2_H
#define HEADER2_H
#include "custom.h"
...
#endif
main.cpp:
#include "header1.h"
#include "header2.h"
...
Will the preprocessor include both "custom.h"-includes or just one?
Is there a need for something like an "#ifninclude"-directive?
Thanks in advance 4 your answers!
Edit: bad English
Last edited by FinallyHere (2011-04-30 20:05:27)
Offline
Offline
Oh thanks! Sorry about that ifndefine thing, you are correct! I will Edit again
Edit:
Output of
$ cpp main.cpp
# 1 "main.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.cpp"
# 1 "header1.h" 1
# 1 "custom.h" 1
# 5 "header1.h" 2
# 2 "main.cpp" 2
# 1 "header2.h" 1
# 3 "main.cpp" 2
int main()
{
return 0;
}
So i guess that means it is only included once! Thank you, issue solved!
Last edited by FinallyHere (2011-04-30 20:07:02)
Offline
Just as something interesting to note:
Both msvc and gcc (and probably a few others) support putting: "#pragma once" at the top of a header file instead of using the #ifndef/#define thing to make sure it is only included once. In both gcc and msvc it is supposed to give minimally faster compiles. Something that you may want to keep in mind for when you are doing large projects, lately I've used it to shave off about 5-10 minutes on a rather long compile at work.
Last edited by Zeist (2011-05-01 17:47:02)
I haven't lost my mind; I have a tape back-up somewhere.
Twitter
Offline
Pages: 1