Guys,
This is a simple question, but I've googled and gnu c'ed myself into confusion
on how to declare and make a simple static const char * have global scope and be
available to a different source file without generating a warning that it is
'defined but not used' in the original file. Here is what I mean. I have a set
of functions and data in files atm_fn.c and atm_fn.h (atmospheric functions) In
atm_fn.h I have:
#include
#include
#include
#ifndef __atm_fn_h__
#define __atm_fn_h__
enum shapes {c172, airfoil, sphere_smooth, sphere_rough, cone, cube45, cyl_long,
airfoil_2, cube, cyl_short, human, plate_flat_3d, plate_flat_2d };
static const char *shape_names[] = {"c172", "airfoil", "sphere_smooth",
"sphere_rough", "cone", "cube45", "cyl_long", "airfoil_2", "cube", "cyl_short",
"human", "plate_flat_3d", "plate_flat_2d" };
<snip>
#endif
I use the function in a test file strarray.c. There I have:
#include
#include
#include
#include
#include "atm_fn.h"
const char *get_shape(int shp);
<snip>
const char *get_shape (int shp) {
return shape_names[shp];
}
<snip>
When I compile it, I get the warning:
22:50 alchemy:~/dev/prg/ccpp/src-c/prj/test> gcc -o strt -Wall -lm -std=c99
strarray.c atm_fn.c
atm_fn.h:14: warning: ‘shape_names’ defined but not used
14 static const char *shape_names[]...
I can't figure out how to get rid of the warning -- or whether I should even
care. Second, the enum gives no warning. I'm sure that there is a rule that I
don't know that says the enum is fine like this, but what about the warning on
'shape_names'?
Since there are a number of functions that will access the 'shape_names' array,
I don't want to duplicate it. What's the best way to handle this? Wrap it in a
struct (class like) data structure and declare a new instance in whatever source
I'm using it in? Dunno -- that's why I'm asking the smart folks :p
--
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse+help@opensuse.org