checking include files

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
BiK
Experienced poster
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

checking include files

Post 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
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post 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.
BiK
Experienced poster
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

Post 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?
sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post 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.
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post 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.
misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post 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...)
Noor
New poster
Posts: 2
Joined: Wed Apr 01, 2015 9:21 am

Re: checking include files

Post 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
Post Reply

Return to “C++”