[systemd-devel] Removing unnecessary includes
Daniele Nicolodi
daniele at grinta.net
Sat Feb 7 05:05:44 PST 2015
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.
Cheers,
Daniele
More information about the systemd-devel
mailing list