I use g++ to compile my programs. With g++ it's not necessary to include all the needed header files from the standard library. This often causes compile errors. What option should I compile my programs with in order to enforce checking that all the necessary header files are included?
Thanks
checking include files
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Your problem is caused by using different version of compiler than OJ does. Headers pull other headers, sometimes in an unexpected way. For instance, in 2.95 <algorithm> pulls <iostream>, but not anymore in 3.3. Switch to gcc 2.95 or include each header that defines funtions from your code (that's a good habit anyway) to avoid compilation errors.
Exatcly including all headers that define functions used in my source code is the point. Sometimes I forget the include files, compile the program with g++, the compiler does not complain because the needed include files are included from somewhere else and then I get a compile error from the judge.
IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
The best you can do is to call g++ --dependencies, but usually that produces huge output that is not useful at all.BiK wrote:IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
I repeat: your problem is caused by differences in dependencies and pulling rules in g++ 2.95 and newer versions. This is not something that can be easily checked.
Krzystof is right. The only thing I can add: unused #includes do not harm you in any way. If you happen to make this kind of mistakes, try using a code template where you #include all header files you may ever need. (There are not that many of them...)Krzysztof Duleba wrote:The best you can do is to call g++ --dependencies, but usually that produces huge output that is not useful at all.BiK wrote:IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
I repeat: your problem is caused by differences in dependencies and pulling rules in g++ 2.95 and newer versions. This is not something that can be easily checked.
Re: checking include files
If you happen to become employing gcc, -Wall may be a very important thing to test. Study upward on the man web site take a look at.
______________________________________________________________________________________________
NoorAlamShahzad
______________________________________________________________________________________________
NoorAlamShahzad