Page 1 of 1

checking include files

Posted: Fri Jun 24, 2005 12:06 am
by BiK
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

Posted: Fri Jun 24, 2005 7:56 am
by Krzysztof Duleba
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.

Posted: Wed Jul 06, 2005 3:31 pm
by BiK
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?

Posted: Wed Jul 06, 2005 3:40 pm
by sumankar
BiK wrote: IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
If you happen to be using gcc, -Wall might be a good thing to try.Read up
on the man page for more info.
HTH
Suman.

Posted: Wed Jul 06, 2005 3:59 pm
by Krzysztof Duleba
BiK wrote:IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
The best you can do is to call g++ --dependencies, but usually that produces huge output that is not useful at all.

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.

Posted: Wed Jul 06, 2005 10:34 pm
by misof
Krzysztof Duleba wrote:
BiK wrote:IS THERE A COMPILE OPTION THAT CHECKS THAT ALL THE HEADER FILES THAT DEFINE FUNCTIONS USED IN MY SOURCE CODE ARE INCLUDED?
The best you can do is to call g++ --dependencies, but usually that produces huge output that is not useful at all.

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...)

Re: checking include files

Posted: Wed Apr 01, 2015 9:26 am
by Noor
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