const variables in header files have "defined but not used" warnings

Viewed 736

I have defined multiple const variables in my header file. When I compile, however, some of them have this defined but not used warning, while some do not.

For instance, the following does not have this warning:

const double var1 = 20;

But the var3 does:

const double var3 = func(var2);

where func() is an inline function defined at the beginning of the same header file, as

inline double func(double x) {
  double d = var5 * pow(x, var4);
  return (d + var6);
}

Here var2 to var6 except var3 are all const variables defined like var1 (no warnings) in the same header file like:

const double var2 = 100;
const double var4 = 50;
const double var5 = 2;
const double var6 = 10;

I am curious why there is a warning at var3.

Also, the warning occurs at var8 only:

extern const int var6;
const int var7 = var6;
const int var8 = var7;

I can disable the warning, or, make all variables as extern const and define them in a source file, which may also exclude the warnings, I guess. But I am just wondering what are the reasons that some are warned but some are not. Thanks.

0 Answers
Related