[FFmpeg-devel] [PATCH] remove unnecessary header files

Måns Rullgård mans
Fri May 30 09:17:04 CEST 2008


Michael Niedermayer <michaelni at gmx.at> writes:

> On Thu, May 29, 2008 at 05:36:06PM +0200, Diego Biurrun wrote:
>> On Thu, May 29, 2008 at 05:24:07PM +0200, Michael Niedermayer wrote:
>> > On Thu, May 29, 2008 at 05:13:11PM +0200, Diego Biurrun wrote:
>> > > On Thu, May 29, 2008 at 07:50:18AM -0700, Erik Hovland wrote:
>> > > > On Thu, May 29, 2008 at 03:38:39PM +0200, Diego Biurrun wrote:
>> > > > > > -#include "ffserver.h"
>> > > > > 
>> > > > > Wrong.
>> > > > > 
>> > > > > > --- a/libavutil/tree.c
>> > > > > > +++ b/libavutil/tree.c
>> > > > > > @@ -19,7 +19,6 @@
>> > > > > >  
>> > > > > >  #include "common.h"
>> > > > > > -#include "log.h"
>> > > > > 
>> > > > > Wrong.
>> > > > > 
>> > > > > I haven't reviewed this completely, but I do not trust the
>> > > > > rest of the changes much.  I applied the correct changes
>> > > > > that I noted above.
>> > > > 
>> > > > Oh ye of little faith :)
>> > > 
>> > > Ummm, just look at tree.c, it uses av_log all over the place, which is
>> > > declared in log.h ...
>> > > 
>> > > After looking again, it seems I was wrong about ffserver.c/ffserver.h.
>> > > I will apply that change as well.
>> > 
>> > Thats what happens when one #includes headers from other headers ...
>> > c files just #include random subsets of the headers they need.
>> > Without headers #including other headers its
>> > compiles -> includes all needed headers, doesnt compile misses a header
>> 
>> This is not the issue we are discussing here, this is about unnecessary
>> headers left lying around...
>
> Without headers #including other headers i can just outcomment all
> #includes from a c file, compile it and gcc will tell me exactly
> what parts are in need of a #include. Its very easy and quick to
> find out what one needs to #include using that method.

I have worked on large projects where some idiot who never dared
identify himself had imposed the rule that header files *never*
include other headers.  In every case, it's been a true nightmare.

Just consider what happens if a header file is changed such that it
depends on something it didn't previously.  Then thousands of source
files have to be updated to include the appropriate header.  If each
header includes everything it needs, there is never a problem like
that.

> With headers #including other headers how can you know that a #include is
> unneeded? gcc wont complain if the #inculde is removed nor will it if it
> is there and unused. You end up reading the source and guessing, a
> timeconsuming and error prone solution.

Including an unnecessary header does no damage.  Not including a
necessary header breaks compilation.  In my experience, the small risk
of having obsolete #include lines in some source files, is far
outweighed by the maintenance hell it avoids.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list