Article View: gnu.gcc.help
Article #42383Re: How to compile in RCS identifiers?
From: Rusty, Paul , Russell
Date: Sat, 16 Dec 1995 00:00
Date: Sat, 16 Dec 1995 00:00
47 lines
2084 bytes
2084 bytes
In message <4as6dg$3ih@ets.cis.brown.edu> you write:
> I'm trying to figure out how to best include RCS version identifier
> strings into the various modules I'm compiling with gcc. I've been
> running into two problems.
>
> 1) With -Wall the compiler warns about the variable being unused
> 2) The compiler optimizes away the existence of the string
Hi James,
I use the following piece of code:
------ RcsId.h ------
#ifdef __GNUC__
// Use Gnu's __attribute__ keyword to suppress warning.
#define ALT_RCSID(Id, Name) \
static const char RCS_ID_##Name[] __attribute__((unused)) = Id
#else
// Grotty method of warning suppression
#define ALT_RCSID(Id, Name) \
static const char RCS_ID_##Name[] = Id; \
static void _DummyUseRCSIdFunction##Name(void) \
{ \
(void)_DummyUseRCSIdFunction##Name; \
(void)RCS_ID_##Name; \
}
#endif /*GNU*/
#define DO_ALT_RCSID(x,y) ALT_RCSID(x,y)
#define RCSID(Id) DO_ALT_RCSID(Id, __LINE__)
------------------
We simply include "RcsId.h" then use
RCSID("$Id");
At the *bottom* of the code. This technique has the advantages that it
suppresses warnings, and also doesn't use the same identifier name for
every source file, allowing C++ templates to be used (where the C source
gets included).
The bad news is that you get a tiny extra function in each .o file.
Hope this at least gives you some ideas,
Rusty.
--
Rusty.Russell@adelaide.maptek.com.au "Engineer? So you drive trains?"
Lies, damned lies, and out-of-date documentation. #include <stddisclm.h>
Technical Details
Message-ID:
<199512160821.SAA05276@gauss.adelaide.maptek.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4as6dg$3ih@ets.cis.brown.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,64570f4dd695fd36 X-Google-Attributes: gid11318c,public From: Rusty.Russell@adelaide.maptek.com.au (Rusty, Paul , Russell) Subject: Re: How to compile in RCS identifiers? Date: 1995/12/16 Message-ID: <199512160821.SAA05276@gauss.adelaide.maptek.com.au> X-Deja-AN: 122048556 distribution: gnu sender: daemon@cis.ohio-state.edu references: <4as6dg$3ih@ets.cis.brown.edu> organization: GNUs Not Usenet newsgroups: gnu.gcc.help