473,396 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

finding redundant #includes to shorten compile time

Are there any C tools that can find redundant #includes in a project,
so as to shorten compile time? Of course, eliminating single
#includes by hand and determining if the recompile fails is one
option, though that is an extremely manual and time-intensive
approach. Thanks,
--
Benjamin
Nov 14 '05 #1
15 2741
Benjamin Rutt <br********@bloomington.in.us> wrote in
news:wc*************@mu.cis.ohio-state.edu:
Are there any C tools that can find redundant #includes in a project,
so as to shorten compile time? Of course, eliminating single
#includes by hand and determining if the recompile fails is one
option, though that is an extremely manual and time-intensive
approach. Thanks,


This trick will eliminate including the same file multiple times per
compile:

/* foo.h
*/
#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED

/* foo.h file contents
*

#endif /* FOO_H_INCLUDED */

--
- Mark ->
--
Nov 14 '05 #2
"Mark A. Odell" <no****@embeddedfw.com> writes:
This trick will eliminate including the same file multiple times per
compile:

/* foo.h
*/
#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED

/* foo.h file contents
*

#endif /* FOO_H_INCLUDED */


Thanks, I'm sorry, I knew of that trick actually, and I've rarely seen
a header file without it...I guess I misstated my question. I was
actually talking about #includeing files that you don't need at all,
not even once, so my using 'redundant' was incorrect. I should have
asked:

How do you find which header files aren't used at all by a single
compilation unit, and can safely be deleted from a the .c file?
--
Benjamin
Nov 14 '05 #3
Benjamin Rutt wrote:
How do you find which header files aren't used at all by a single
compilation unit, and can safely be deleted from a the .c file?


I believe this falls under the topic of "lint," such as declaring unused
variables, code blocks that do nothing (ie "if (0 == 1) {[...]}", etc...),
redundant stuff ("a = 1; a = 5"), and all the other junk that accumulates
as projects evolve.

I would use a lint checker for that.

I have used the Gimpel lint checker (www.gimpel.com) quite successfully,
I'm sure there are others including free ones.

--
gabriel
Nov 14 '05 #4
Mark A. Odell wrote:
Benjamin Rutt <br********@bloomington.in.us> wrote in
news:wc*************@mu.cis.ohio-state.edu:

Are there any C tools that can find redundant #includes in a project,
so as to shorten compile time? Of course, eliminating single
#includes by hand and determining if the recompile fails is one
option, though that is an extremely manual and time-intensive
approach. Thanks,

This trick will eliminate including the same file multiple times per
compile:

/* foo.h
*/
#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED

/* foo.h file contents
*

#endif /* FOO_H_INCLUDED */


The file opening time may be reduced by using:
#ifndef FOO_H_INCLUDED
#include "foo.h"
#endif

Finding and opening a file is one of the major items
for compilation times. Also, in Mark's version, the
compiler must scan all the code looking for the
#endif, which takes time.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #5
Thomas Matthews <Th****************************@sbcglobal.net> wrote in
news:tK*******************@newssvr16.news.prodigy. com:
This trick will eliminate including the same file multiple times per
compile:

/* foo.h
*/
#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED

/* foo.h file contents
*

#endif /* FOO_H_INCLUDED */


The file opening time may be reduced by using:
#ifndef FOO_H_INCLUDED
#include "foo.h"
#endif

Finding and opening a file is one of the major items
for compilation times. Also, in Mark's version, the
compiler must scan all the code looking for the
#endif, which takes time.


Doesn't this approach become cumbersome and error prone with many source
files and many header files? The standard way I mentioned means that the
user of the header file can blissly include the header file without fear
of multiple definition warnings.

--
- Mark ->
--
Nov 14 '05 #6
On Thu, 05 Feb 2004 11:49:31 -0500, Benjamin Rutt
<br********@bloomington.in.us> wrote in comp.lang.c:
Are there any C tools that can find redundant #includes in a project,
so as to shorten compile time? Of course, eliminating single
#includes by hand and determining if the recompile fails is one
option, though that is an extremely manual and time-intensive
approach. Thanks,


PC-Lint. http://www.gimpel.com.

Worth every penny, once you get the configuration files set up for
your code.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #7
Thomas Matthews wrote:
The file opening time may be reduced by using:

#ifndef FOO_H_INCLUDED
#include "foo.h"
#endif

Finding and opening a file is one of the major items
for compilation times. Also, in Mark's version, the
compiler must scan all the code looking for the
#endif, which takes time.


No!

The C preprocessor remembers the names of *idempotent* header files
and will *not* attempt to find, open or read them a second time.
Your suggestion is out-of-date and no longer necessary or useful.

Nov 14 '05 #8
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> writes:
Thomas Matthews wrote:
The file opening time may be reduced by using:
#ifndef FOO_H_INCLUDED
#include "foo.h"
#endif
Finding and opening a file is one of the major items
for compilation times. Also, in Mark's version, the
compiler must scan all the code looking for the
#endif, which takes time.


No!

The C preprocessor remembers the names of *idempotent* header files
and will *not* attempt to find, open or read them a second time.
Your suggestion is out-of-date and no longer necessary or useful.


No, some implementations of the C preprocessor do this. I have no
idea how many, but it's unwise to assume that they all do. (Not that
it matters, since there's no real functional difference.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #9
E. Robert Tisdale wrote:
The C preprocessor remembers the names of *idempotent* header files
and will *not* attempt to find, open or read them a second time.
Your suggestion is out-of-date and no longer necessary or useful.


Cammon, you know better than that! Of course, _some_ implementations might
do this, but then if you want to bring up implementation-specific features,
then I could chime in and say we're all fool for discussing this topic
given that precompiled headers exist.

--
gabriel
Nov 14 '05 #10
Keith Thompson wrote:
E. Robert Tisdale writes:
Thomas Matthews wrote:
The file opening time may be reduced by using:
#ifndef FOO_H_INCLUDED
#include "foo.h"
#endif
Finding and opening a file is one of the major items
for compilation times. Also, in Mark's version, the
compiler must scan all the code looking for the
#endif, which takes time.


No!

The C preprocessor remembers the names of *idempotent* header files
and will *not* attempt to find, open or read them a second time.
Your suggestion is out-of-date and no longer necessary or useful.


No, some implementations of the C preprocessor do this.
I have no idea how many, but it's unwise to assume that they all do.
(Not that it matters, since there's no real functional difference.)


It is *unwise* to cobble your code
just to accommodate an inferior C preprocessor.
If your C preprocessor does not implement this optimization,
it's time to shop around for a better C compiler.

Nov 14 '05 #11
gabriel wrote:

E. Robert Tisdale wrote:
The C preprocessor remembers the names of *idempotent* header files
and will *not* attempt to find, open or read them a second time.
Your suggestion is out-of-date and no longer necessary or useful.


Cammon, you know better than that! Of course, _some_ implementations might
do this, but then if you want to bring up implementation-specific features,
then I could chime in and say we're all fool for discussing this topic
given that precompiled headers exist.

You have to understand that Trollsdale believes his implementation is
the only one in the world. So anything true for it is true for all.

Brian Rodenborn
Nov 14 '05 #12
E. Robert Tisdale wrote:

<snip>
It is *unwise* to cobble your code
just to accommodate an inferior C preprocessor.
If your C preprocessor does not implement this optimization,
it's time to shop around for a better C compiler.


Some platforms have a limited number of C implementations (e.g. just one or
two). If none of the implementations available for a particular platform
implement the feature you desire, what would you recommend? Changing the
platform?

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #13
Richard Heathfield wrote:
platform implement the feature you desire, what would you recommend?
Changing the platform?


Write your own compiler, like real men do!

Just kidding...

--
gabriel
Nov 14 '05 #14
In <wc*************@mu.cis.ohio-state.edu> Benjamin Rutt <br********@bloomington.in.us> writes:
Are there any C tools that can find redundant #includes in a project,
so as to shorten compile time? Of course, eliminating single
#includes by hand and determining if the recompile fails is one
option, though that is an extremely manual and time-intensive
approach. Thanks,


The easiest approach is not to include unnecessary headers in the first
place.

Anyway, unless they reside on a particularly slow medium, headers increase
the compilation time by an insignificant amount.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #15
Richard Heathfield wrote:
E. Robert Tisdale wrote:

<snip>
It is *unwise* to cobble your code
just to accommodate an inferior C preprocessor.
If your C preprocessor does not implement this optimization,
it's time to shop around for a better C compiler.


Some platforms have a limited number of C implementations (e.g.
just one or two). If none of the implementations available for a
particular platform implement the feature you desire, what would
you recommend? Changing the platform?


Hell no. Simply advise Trollsdale and he will have a compiler
ready for you in the next 48 hours. It will have excellent
specifications. A minor problem might be that it won't meet them,
and that it reports success or failure by crashing. A
compensation may be that it is subject to buffer overruns, so with
a bit of practice you can write a source that patches it on the
fly.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: max(01)* | last post by:
hi everybody. suppose that code-1.py imports code-2.py and code-3.py (because it uses names from both), and that code-2.py imports code-3.py. if python were c, code-1.c should only *include*...
4
by: Aaron W. West | last post by:
Timings... sometimes there are almost too many ways to do the same thing. The only significant findings I see from all the below timings is: 1) Integer math is generally fastest, naturally....
10
by: Chris Gordon-Smith | last post by:
I am currently revisiting the code of a C++ application and restructuring the code where appropriate to make it consistent with the overall logical design. As part of this, I am looking at the...
23
by: Mark Dickinson | last post by:
I have a simple 192-line Python script that begins with the line: dummy0 = 47 The script runs in less than 2.5 seconds. The variable dummy0 is never referenced again, directly or indirectly,...
7
by: ralphNOSPAM | last post by:
Is there a PHP script that can find unused variables? I'd like to 'clean up' my scripts. Thanks...
2
by: David Muoio | last post by:
I am trying to validate an XML file against an XSD that is stored in the assembly as an embedded resource. I can get it to work as long as the XSD does not include other XSDs. After a fair amount...
8
by: Jim | last post by:
Hi: Do we have some common style for includes when working on a project with lots of c and h files. Wat I mean is do we have a rule in C when a file includes several files and those file in turn...
31
by: smachin1000 | last post by:
Hi All, Does anyone know of a tool that can automatically analyze C source to remove unused #includes? Thanks, Sean
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.