Re: #include optimization
Ramesh Natarajan wrote:[color=blue]
>
> (2) The second problem is un-necessary #includes. Over a period of time
> the
> developers have got a set of #includes that they add to the files
> without
> thinking!!
>
> for eg: consider
>
> #include<stdio. h>
> #include<sys/types.h>
> #include<sys/socket.h>
> int main(int argc,char** argv){
> printf("Hello World\n");
> }
>
> Here the includes for types and socket is unnecessary.
>
> This involves 2 file opens on this level that could be avoided.
>
> I want to fix this also.
>
> But I am unable to come out with some solution...[/color]
Hmm. Just a quick shot. The idea is:
Write a program which reads and modifies a source file. The program
drops one of the includes and afterwards starts the compiler on the
modified source. If the compiler doesn't complain, the include was
unnecesary and is permanenlty dropped. If the compiler emits an error
then the drop is undone.
Your program checks every include in this way and thus keeps only the
needed ones.
--
Karl Heinz Buchegger
kbuchegg@gascad .at
Ramesh Natarajan wrote:[color=blue]
>
> (2) The second problem is un-necessary #includes. Over a period of time
> the
> developers have got a set of #includes that they add to the files
> without
> thinking!!
>
> for eg: consider
>
> #include<stdio. h>
> #include<sys/types.h>
> #include<sys/socket.h>
> int main(int argc,char** argv){
> printf("Hello World\n");
> }
>
> Here the includes for types and socket is unnecessary.
>
> This involves 2 file opens on this level that could be avoided.
>
> I want to fix this also.
>
> But I am unable to come out with some solution...[/color]
Hmm. Just a quick shot. The idea is:
Write a program which reads and modifies a source file. The program
drops one of the includes and afterwards starts the compiler on the
modified source. If the compiler doesn't complain, the include was
unnecesary and is permanenlty dropped. If the compiler emits an error
then the drop is undone.
Your program checks every include in this way and thus keeps only the
needed ones.
--
Karl Heinz Buchegger
kbuchegg@gascad .at
Comment