Re: How do I inhibit warning 528?
From: Robert (robertsadress_at_hotmail.com)
Date: 01/28/04
- Next message: ark: "Re: integer division"
- Previous message: James Dow Allen: "Re: integer division"
- In reply to: Alan Balmer: "Re: How do I inhibit warning 528?"
- Next in thread: Rob Thorpe: "Re: How do I inhibit warning 528?"
- Reply: Rob Thorpe: "Re: How do I inhibit warning 528?"
- Reply: Alan Balmer: "Re: How do I inhibit warning 528?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Jan 2004 23:08:03 -0800
Alan Balmer <albalmer@att.net> wrote in message news:<0m0d10d8dmqfh1gnt9alg73i428hhkvs7v@4ax.com>...
> On Tue, 27 Jan 2004 13:48:38 GMT, CBFalconer <cbfalconer@yahoo.com>
> wrote:
>
> >Robert wrote:
> >> Emmanuel Delahaye <emdelYOURBRA@noos.fr> wrote in message
> >> > In 'comp.lang.c', robertsadress@hotmail.com (Robert) wrote:
> >> >
> <snip>
> >> 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.
>
> Since it's declared static, it doesn't need to have extern linkage,
> and in fact, the uses in the two files may conflict. Apparently
> there's some concern that this variable have the same initial value in
> both of the programs where it's used, so I would do something like
>
> #define MY_SPECIAL_VALUE 3
>
> in the header file, then each file that needs it declares
>
> static int my_const_var = MY_SPECIAL_VALUE;
>
> (Actually, I'm suspicious that this program doesn't even need a
> variable, but can't tell without seeing the rest of it.)
I guess that it could conflict if the 'const' is overridden somehow,
otherwise it is ok, eccept that it is unused in file3.c.
'#define MY_SPECIAL_VALUE 3' has two major drawbacks as I see it:
1) No type checking.
2) Filths down the global name space.
Your last sentence is a key I think. I do need constants, not
variables, and I need to implement them in a good manner. Say things
like error codes, breakpoints and max values. You don't hard code them
everywhere. You make constants and use there names. That way you only
need to change the value in one place.(candidate for configuration)
Best regards,
Robert
- Next message: ark: "Re: integer division"
- Previous message: James Dow Allen: "Re: integer division"
- In reply to: Alan Balmer: "Re: How do I inhibit warning 528?"
- Next in thread: Rob Thorpe: "Re: How do I inhibit warning 528?"
- Reply: Rob Thorpe: "Re: How do I inhibit warning 528?"
- Reply: Alan Balmer: "Re: How do I inhibit warning 528?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]