This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC warnings for unused global variables
cgd@broadcom.com writes:
> FYI, some of "the BSD folks" have already made substantial changes
> w.r.t. these markings, e.g. in NetBSD we do:
>
> #include <sys/cdefs.h>
> ...
> __COPYRIGHT(
> "@(#) Copyright (c) 1989, 1993\n\
> The Regents of the University of California. All rights reserved.\n");
> ...
> __RCSID("$NetBSD: cat.c,v 1.35 2002/09/13 18:07:52 thorpej Exp $");
> ...
>
> That lets us neatly handle multiple object formats easily while still
> using features like placing the strings in non-loaded sections when
> using ELF. ("Why waste the RAM?" 8-) It also means that we can apply
> (have applied!) __attribute__((__unused__)) nearly everywhere fairly
> easily.
Hmm. I could give you #pragma GCC ident (semantically identical to
#ident) which would let you do
#define __RCSID(str) _Pragma("GCC ident " #str)
The strings would all be put neatly into the .comment section, and I
believe we can guarantee no warnings ever. (_Pragma being a C99
feature, it would normally be warned about under -std=c89, but the
general suppression of warnings for code in system headers should
suffice to shut it up.)
zw