public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to warn on unused preprocessor defines...
@ 2008-01-11 15:34 charlie
  2008-01-11 15:43 ` Andrew Bell
  2008-01-12  7:34 ` Marc Weber
  0 siblings, 2 replies; 6+ messages in thread
From: charlie @ 2008-01-11 15:34 UTC (permalink / raw)
  To: gcc-help


How can I tell gcc/cpp to warn on (or in some other way point out) 
unused preprocessor defines?

Thanks.

- Chuck


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: how to warn on unused preprocessor defines...
  2008-01-11 15:34 how to warn on unused preprocessor defines charlie
@ 2008-01-11 15:43 ` Andrew Bell
  2008-01-12  7:34 ` Marc Weber
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Bell @ 2008-01-11 15:43 UTC (permalink / raw)
  To: uber; +Cc: gcc-help

On Jan 10, 2008 1:51 PM, charlie <uber@juun.com> wrote:
>
> How can I tell gcc/cpp to warn on (or in some other way point out)
> unused preprocessor defines?

Comment them out and see if the compiler complains.

-- 
Andrew Bell
andrew.bell.ia@gmail.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: how to warn on unused preprocessor defines...
  2008-01-11 15:34 how to warn on unused preprocessor defines charlie
  2008-01-11 15:43 ` Andrew Bell
@ 2008-01-12  7:34 ` Marc Weber
  2008-01-12 22:34   ` John (Eljay) Love-Jensen
  1 sibling, 1 reply; 6+ messages in thread
From: Marc Weber @ 2008-01-12  7:34 UTC (permalink / raw)
  To: gcc-help

>  How can I tell gcc/cpp to warn on (or in some other way point out) unused 
>  preprocessor defines?

What do you mean by unused?
Used but never set/defined (eg by configure)
or defined but not present in any
#ifdef DEFINE=XX
#endif ?

If it's the second case you can use a simple tool such as grep to get a
list of all defines (filter ^#define ..)
Then you can remove those found files from the code base and grep the
result. If there are no occurences left it's safe to remove it..
If there are you have to manually check wither the occurences are in
comments etc.
So perhaps this helps you find of all not used defines.

Marc Weber

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: how to warn on unused preprocessor defines...
  2008-01-12  7:34 ` Marc Weber
@ 2008-01-12 22:34   ` John (Eljay) Love-Jensen
  0 siblings, 0 replies; 6+ messages in thread
From: John (Eljay) Love-Jensen @ 2008-01-12 22:34 UTC (permalink / raw)
  To: Marc Weber, gcc-help

> If it's the second case you can use a simple tool such as grep to get a list of all defines (filter ^#define ..)

Or use the preprocessor to generate the list of #define for you:

gcc -E -dM Foo.c | sort > Foo.dM

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: how to warn on unused preprocessor defines...
  2008-01-11 18:00 charlie
@ 2008-01-12  1:19 ` Tony Wetmore
  0 siblings, 0 replies; 6+ messages in thread
From: Tony Wetmore @ 2008-01-12  1:19 UTC (permalink / raw)
  To: uber; +Cc: gcc-help

charlie wrote:
 > There are hundreds of them that are suspect.  (project inherited from
 > someone else who went a little crazy with the #defines... #defines we
 > will never ever use)
 >
 > That's the problem.  I want the compiler to help me out a little.

Try using "-Wunused-macros", documented in the man pages for gcc and cpp.

I haven't tried it, but that might do what you want.

Be prepared for a lot of output, because it will only be able to tell 
you which macros are used in each compilation unit, not across your 
entire project.  So, presumably it will tell you about the same unused 
macros in every single source file that you compile.

--
Tony Wetmore


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: how to warn on unused preprocessor defines...
@ 2008-01-11 18:00 charlie
  2008-01-12  1:19 ` Tony Wetmore
  0 siblings, 1 reply; 6+ messages in thread
From: charlie @ 2008-01-11 18:00 UTC (permalink / raw)
  To: gcc-help


There are hundreds of them that are suspect.  (project inherited from 
someone else who went a little crazy with the #defines... #defines we 
will never ever use)

That's the problem.  I want the compiler to help me out a little.

Thanks.

- chuck



On January 10, 2008, Andrew Bell wrote:

> On Jan 10, 2008 1:51 PM, charlie <uber@juun.com> wrote:
>> 
>> How can I tell gcc/cpp to warn on (or in some other way point out)
>> unused preprocessor defines?
> 
> Comment them out and see if the compiler complains.
> 
> -- 
> Andrew Bell
> andrew.bell.ia@gmail.com
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-11 12:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-11 15:34 how to warn on unused preprocessor defines charlie
2008-01-11 15:43 ` Andrew Bell
2008-01-12  7:34 ` Marc Weber
2008-01-12 22:34   ` John (Eljay) Love-Jensen
2008-01-11 18:00 charlie
2008-01-12  1:19 ` Tony Wetmore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).