Re: compiling multiple source files and static functions

From: David Resnick (dresnick_at_N.o.S.p.A.m.p.l.e.a.s.e.alum.mit.edu)
Date: 01/28/05


Date: Fri, 28 Jan 2005 09:07:39 -0500

beetle wrote:
> Hi,
>
> I'm compiling multiple source files which hold some static
> functions(). The compiler `gcc' won't compile them and spit's errors
> like:
>
> warning: `cmpr' defined but not used
> undefined reference to `cmpr'
>
> What options should I give gcc to make sure that it knows that the
> static functions are used within the same program ?
>
> Thnkx.. a lot.
>
> Beetle.

Um, if it is a static function and not referenced within that source
file than it can't be used (it isn't available to the linker, other
translation units don't know about it). Only way a static function
can normally be used outside its file is if you passed a pointer to it
back via some function, in which case gcc wouldn't gripe. That said,
I think you are looking for the gcc unused attribute:.

#include <stdio.h>
static void dead_func(void) __attribute__ ((unused));
int main(void)
{
   puts("hello world");
   return 0;
}
static void dead_func(void)
{
   puts("I don't get called");
}

Above gets no complaints with -Wall.

-David



Relevant Pages

  • Re: Anyone interested in building a vms-like OS?
    ... then you have a good reason for preferring the BSD license over GPL. ... geeks :-) is that it is fast, 5-10 times faster than gcc, while still ... Compiling 10 times faster with almost no optimization does not ... It is compiling much faster but doing less optimizations. ...
    (comp.os.vms)
  • Conexant HCF Modem Problems
    ... Conexant HCF modem, which is a "controllerless" modem, not a HSF which ... files to compile and to install but the problem is when I try to config ... compiling (gcc) mod_osspec.c ...
    (comp.os.linux.hardware)
  • [ANN] macstl 0.1.5 -- Xcode compatibility
    ... The new version also has fixes for older gcc ... Now builds with Xcode 1.0. ... Fixed altivec functions not compiling in gcc 3.1: ...
    (comp.lang.cpp)
  • Re: Finally one site with all the C fundas
    ... was pretty lenient and we did not actively pursue compiling the tool ... the CPU/memory architecture doesn't allow unaligned accesses. ... Also gcc 3.3.6 would have spotted that if invoked with the '-W' ... Casting the return value of mallocis never necessary ...
    (comp.lang.c)
  • Re: A bug in gnat/gcc 3.3.3?
    ... > Compiling ASIS and GLADE for a newer version isn't that difficult - ... harping on GCC 3.4, but I'd like reports about ASIS and GLADE for GCC ... GCC 3.4 does not "have" PolyORB, ...
    (comp.lang.ada)