From owner-freebsd-current Wed Jul 31 04:42:23 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id EAA24391 for current-outgoing; Wed, 31 Jul 1996 04:42:23 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id EAA24383 for ; Wed, 31 Jul 1996 04:42:13 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.12/8.6.9) id VAA24793; Wed, 31 Jul 1996 21:34:37 +1000 Date: Wed, 31 Jul 1996 21:34:37 +1000 From: Bruce Evans Message-Id: <199607311134.VAA24793@godzilla.zeta.org.au> To: freebsd-current@FreeBSD.ORG, syssgm@devetir.qld.gov.au Subject: Re: `const char rcsid[]' vs -traditional Sender: owner-current@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >I find: > static const char rcsid[] = ... >How long will it be before the ANSI compilers start discarding unreferenced >static data? Or is "rcsid" already a special case in gcc? :-) There's nothing to stop ANSI compilers from discarding unreferenced data, but declaring static variables as `const' is a documented way of stopping gcc from discarding them. At least, the following macro is a documented way for gcc-2.6.3: #define USE(var) \ static void *const use_##var = (&use_##var, &var, 0) This method also works for functions. It is used in MAKE_SET() in . Unfortunately, gcc with maximal warnings generates many warnings for this macro. E.g., when it is applied to static int x; USE(x); z.c:4: warning: initialization makes pointer from integer without a cast z.c:4: initializer element is not constant There are even more warnings (which actually occur thousands of times for compiling the kernel) for gcc-2.7.2. The USE() macro is no longer documented for gcc-2.7.2; you are supposed to use the `unused' attribute instead: static const int x __attribute__((__unused__)); The `unused' attribute doesn't work for gcc-2.6.3 so it will need to be used in a macro that expands to the attribute version only for recent versions of gcc. The `unused' attribute doesn't work completely for functions: static void x(void) __attribute__((__unused__)); static void x(void) {} This works right for -O2 but the function still gets deleted for -O3. The function probably needs to referenced via a pointer to keep it. MAKE_SET() fails to do this for the function pointer arg because the function pointer arg is only referenced in assembler. >Should we switch to #ident? It doesn't do anything useful on 2.1.5, but >we could fix that. > #ident "$Id: frobble.c,v ..." >What does the C standard say about #ident? Has anyone put a copy of the >standard on the web? #ident is a syntax error. The standard won't be put on the web until its owners figure out how to charge for it there :-(. Anyway, we shouldn't use #ident because it is impossible to hide the details in a macro. Bruce