Re: How do I inhibit warning 528?

From: Robert (robertsadress_at_hotmail.com)
Date: 01/28/04


Date: 27 Jan 2004 22:50:46 -0800

CBFalconer <cbfalconer@yahoo.com> wrote in message news:<4016623B.3091A0FA@yahoo.com>...
> Robert wrote:
> > Emmanuel Delahaye <emdelYOURBRA@noos.fr> wrote in message
> > > In 'comp.lang.c', robertsadress@hotmail.com (Robert) wrote:
> > >
> > > > Flexelint says:
> > > >
> > > > Warning 528: Symbol 'MY_STATIC_CONST_INT_VAR' (line 426, file
> > > > headfile.h) not referenced
> > >
> > > Can you post the exact line where 'MY_STATIC_CONST_INT_VAR' is
> > > defined? Seems to be the definition of a static objet. Sounds
> > > like bad design...
> >
> > Well, I think it is bad design.
> >
> > head.h has the declaration
> > static const int MY_STATIC_CONST_INT_VAR = 3;
> >
> > file1.c, file2.c and file3.c all includes head.h
> > but only file1.c and file2.c makes use of MY_STATIC_CONST_INT_VAR.
> >
> > As I see it, there are some different ways to go.
> >
> > 1) leave it as is, never mind about a local variable that is not
> > used in file3.c.
> >
> > 2) #define MY_STATIC_CONST_INT_VAR 3 or
> > 3) #define MY_STATIC_CONST_INT_VAR (int)3
> > 4) put the declaration in one of the .c files and declare it
> > extern in the other .c files that makes use of the constant.
> >
> > I would prefer 4) as I think that gives best type checking.
> > Or are 3) as good?
> > Or is there better ways?
>
> Declare it extern in the header file (no initialization).
> Actually declare and initialize it in one of the two .c files that
> use it. There should never have been an actual data declaration
> in the .h file in the first place.
>
> Net changes: modify one line, add one line in some .c file.

But is it ok to declare it extern in the header file?
I guess that it would lead to the same situation,
that file3.c sees it as a declared but unused variable(constant).

/Robert



Relevant Pages

  • Re: confused about extern use
    ... going to achieve by declaring it as extern in the header file a.h. ... composed on one or more compilation units. ... Essentially you *declare* the type wherever it is ...
    (comp.lang.c)
  • Re: keyword extern
    ... > declared multiple times using extern in all the files file2.c ... NEVER, ever, define a variable in a header file. ... declare it with the "extern" qualifier in the header file for the ... misuse. ...
    (comp.lang.c)
  • Re: global data
    ... definition that has initialization, ... for initialization is the one that does not have the extern attribute. ... In C if you declare an external variable (or precisely, ... I.e. all references and no definition, ...
    (comp.lang.fortran)
  • Re: Exported function mangaled name
    ... with many DLLs and supporting this for Windows 32 bit ... that header file; ... You have to declare the function the same way in your .cpp file as in ... extern "C" { ...
    (microsoft.public.vc.mfc)
  • Re: How to declare functions in so to be accessable to applications
    ... >> But the application tells my, that it didn't find the entry point ... > Your header file that the application uses, ... > prototype normally, not as an extern. ... When you declare it extern, ...
    (comp.unix.programmer)