How do I inhibit warning 528?

R

Robert

Hi,

Flexelint says:

Warning 528: Symbol 'MY_STATIC_CONST_INT_VAR' (line 426, file
headfile.h) not referenced

I do understand why, but I'm not sure I wanna change the code to
remove the warning. How do I inhibit the warning for just
MY_STATIC_CONST_INT_VAR?


FLINT_INHIBIT += -e528

inhibit all warnings of this type, and that is to much.


FLINT_INHIBIT += -efunc\(528,Func\)

demands that the problem is in a specific function,
(even though the documentation says inhibition of symbol?)

Any ideas?

/Robert
 
M

Mark A. Odell

(e-mail address removed) (Robert) wrote in

Warning 528: Symbol 'MY_STATIC_CONST_INT_VAR' (line 426, file
headfile.h) not referenced

I do understand why, but I'm not sure I wanna change the code to
remove the warning. How do I inhibit the warning for just
MY_STATIC_CONST_INT_VAR? [snip]
Any ideas?

Ask in a newsgroup that discusses your compiler or Lint package.
Inhibiting warnings has nothing to do with the C *language* which we
discuss here.
 
A

Artie Gold

Robert said:
Hi,

Flexelint says:

Warning 528: Symbol 'MY_STATIC_CONST_INT_VAR' (line 426, file
headfile.h) not referenced

I do understand why, but I'm not sure I wanna change the code to
remove the warning. How do I inhibit the warning for just
MY_STATIC_CONST_INT_VAR?


FLINT_INHIBIT += -e528

inhibit all warnings of this type, and that is to much.


FLINT_INHIBIT += -efunc\(528,Func\)

demands that the problem is in a specific function,
(even though the documentation says inhibition of symbol?)

Any ideas?

Sure. Find a place where questions about `Flexelint' is topical. This
isn't it.

HTH,
--ag
 
E

Emmanuel Delahaye

In said:
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...
 
R

Robert

Emmanuel Delahaye said:
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?

/Robert
 
C

CBFalconer

Robert said:
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.
 
A

Alan Balmer

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.)
 
R

Robert

CBFalconer said:
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
 
R

Robert

Alan Balmer said:
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
 
R

Rob Thorpe

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.

I don't agree.

1) Since when do contants have a type?
Most constants are numbers relevant to certain algorithms in the code,
sometimes they are arbitrary information brought in from outside the
program. Sometimes they are sizes of fixed length arrays. In almost
all these circumstances there is no good reason to type them.
If they absolutely do need a type and they could be misunderstood or
misused without one, then use "const type ...".

2) "Filths down the global name space."
What do you mean? A preprocessor constant declared in an include file
is seen in every file in which that file is included, it is not
global. Unless you include everything everywhere, which you should
not. So it does not mess up the global namespace.
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)

Yes
 
P

pete

Rob said:
I don't agree.

1) Since when do contants have a type?

Since the begining:
sizeof 0.0 == sizeof(double)
sizeof 0 == sizeof(int)
sizeof 0.0f == sizeof(float)
sizeof((char)0) == 1
sizeof((char)0 + (char)0) == sizeof(int)
1 & 1 == 1
(-1 & 1) == implementation defined, depending on
the representation of negative int values.
 
A

Alan Balmer

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.
How so? When you declare "static int whatever_name_you_like" the
compiler will type-check no matter how you initialize it.

2) Filths down the global name space.
Pick whatever name you like.
 
M

Mark McIntyre

On 27 Jan 2004 22:50:46 -0800, in comp.lang.c ,
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).

extern is a tentative declaration. No object is created, it tells the
compiler that the object exists elsewhere. So you should not get a
warning about it being unused, since its not actually defined in the
relevant module.
 
R

Rob Thorpe

pete said:
Since the begining:
sizeof 0.0 == sizeof(double)
sizeof 0 == sizeof(int)
sizeof 0.0f == sizeof(float)
sizeof((char)0) == 1
sizeof((char)0 + (char)0) == sizeof(int)
1 & 1 == 1
(-1 & 1) == implementation defined, depending on
the representation of negative int values.

You are completely right and I'm very wrong.

1) Should have been:
I don't think of program/module wide constants as having a type
I would write

#define FOO 45.345

Then make it into whatever type is needed when it is used, normally
coercion does this and casts aren't necessary.
 
R

Robert

Artie Gold said:
Sure. Find a place where questions about `Flexelint' is topical. This
isn't it.

HTH,
--ag

Hey you, strong man. Do you have any suggestion?
Or are your HTH just a joke?

/Robert
 
M

Mark McIntyre

On 29 Jan 2004 04:07:52 -0800, in comp.lang.c ,

(something or other. )

Since you're asking about how to stop flexelint complaining, and
flexelint is not C, I think its fair to say that...

...... this is a reasonable comment.
Hey you, strong man. Do you have any suggestion?
Or are your HTH just a joke?

He did help, He told you to ask in the right place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top