-Wunused-macros

Neil Booth neil@daikokuya.co.uk
Tue Jul 23 14:41:00 GMT 2002


Fergus Henderson wrote:-

> I haven't had a look at your patch yet, but I'm in favour of the idea.

Ok; I've had a generally favourable response (on and off list).
 
> One question: will we get warnings for cases where
> a macro is only used in a conditionally compiled piece of
> code for which the condition is false?
> E.g.
> 
> 	#define FOO ...
> 
> 	#ifndef __GNUC__
> 	   ... FOO ...
> 	#endif

This macro will be reported as unused.  I actually think that's a
good idea - it encourages making the definition conditional along
with the code that uses it.  Do you agree?

There are some cases of this in GCC; but I've ignored them so
far.

> > I've not added it to -Wunused, since -Wall implies -Wunused,
> > and I think this option may be too pricey to go there.
> 
> Do you have any measurements of the cost?

It's a hashtable scan, and so is linear in the size of the hash table.
The size of the hash table is (roughly) linear in the number of
identifiers; but it tends to come in a minimum size.  The number of
cycles per identifier is low; an indirect call and a couple of if
statements.  I've not timed it, but soon you'll be able to if you're
curious 8-)

On an individual compile it's negligible, but e.g. GCC's bootstrap
uses -Wall, and it could add, umm, a 0.2% tops I'd guess
(based on the fact that all of CPP is normally <2% of bootstrap time).
Maybe it's not worth worrying about and I should put it in -Wunused
(and therefore -Wall) too.

There is quite a bit of noise in YACC-generated files because they
tend to define 10 or 20 macros that aren't used.

Neil.



More information about the Gcc-patches mailing list