William Payne wrote:
Hello, when compiling my program I get a warning in one of my header files
(globals.h) each time a source file includes it.
The warning reads:
globals.h:28: warning: `const char*g_mdi_child_class_name' defined but not
used
line 28 of globals.h is:
static const char* g_mdi_child_class_name = "MDIChildClass";
Why do I get this warning for this variable? It's used at three places
throughout the program. I have two static const int variables in globals.h
but I don't get any warnings regarding those. I also have five extern
variables.
Focus on the 'static'. That means each translation unit (.cpp file) gets its
own copy of the variable (unless it's a compile-time constant, which it is
not, because the 'const' is on the left side of the star *).
So each of your translation units, except the three that use the variable,
get a copy of it that they don't use.
Your 'static const int' globals, by contrast, are compile-time constants, so
the compiler logically unifies them, and doesn't grant each translation unit
a separate one.
Write this:
static const char g_mdi_child_class_name[] = "MDIChildClass";
That declares intent better anyway. Nobody expected to re-point the former
pointer.
--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces