[systemd-devel] Removing unnecessary includes

Thomas H.P. Andersen phomes at gmail.com
Sat Feb 7 06:38:04 PST 2015


On Sat, Feb 7, 2015 at 2:37 PM, Ronny Chevalier
<chevalier.ronny at gmail.com> wrote:
> 2015-02-07 14:05 GMT+01:00 Daniele Nicolodi <daniele at grinta.net>:
>> On 07/02/15 10:29, Thomas H.P. Andersen wrote:
>>> I am looking at ways to automatically trim the unnecessary includes.
>>> One way to do it is a script[1] which simply tests if the compile
>>> still works after removing each include one at a time. It does this in
>>> reverse order for all includes in the .c files. Using -Werror we catch
>>> any new warnings too.
>>
>> Hello Thomas,
>>
>> this approach is not correct: in this way each source file would not be
>> required to include the headers included by other files included before.
>> For example, if header file "a.h" includes "shared.h" and implementation
>> file requires the definitions of "a.h" and "shared.h", only the first
>> dependency would be detected by this method.
>>
>> However, it is good practice to include all the required header files,
>> whether those are already included by others or not.
>>
>
> Hi,
>
> I agree with Daniele. If you want to include the proper headers in
> each file maybe you can use include-what-you-use [0], but this is a
> rather recent project with lots of issues that will force you to do a
> lots of manual review.
>
> [0] https://code.google.com/p/include-what-you-use/

Looks useful. Will take a look.

>> Cheers,
>> Daniele
>>
>> _______________________________________________
>> systemd-devel mailing list
>> systemd-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list