Hello, All!
I'm implementing function parsing config file, which look like this:
# this is comment
port=10000
path=/var/run/dump.pid
....
Declared the type
#define BUFLEN 1024
typedef struct config_s {
char parameter[BUFLEN];
void *value;
} config_t;
....
#define N 10 /* number of parameters in config file */
config_t conf[N];
....
strcpy(conf[0].parameter, "debug");
conf[0].value = value;
....
It's supposed to keep parameter name and it's value, which can be different
type (string or unsigned int), that's why I use 'void*' pointer. But at this
point I faced with the problem of type casting. If I call, for example:
strcpy(conf[5].parameter, "port");
conf[PORT].value = (unsigned short)value;
than get compiler's warning:
config.c:61: warning: cast from pointer to integer of different size
config.c:61: warning: assignment makes pointer from integer without a cast
I'd wish to keep values of different types in my structure. How is better
and correct to fulfil this?
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
I'm implementing function parsing config file, which look like this:
# this is comment
port=10000
path=/var/run/dump.pid
....
Declared the type
#define BUFLEN 1024
typedef struct config_s {
char parameter[BUFLEN];
void *value;
} config_t;
....
#define N 10 /* number of parameters in config file */
config_t conf[N];
....
strcpy(conf[0].parameter, "debug");
conf[0].value = value;
....
It's supposed to keep parameter name and it's value, which can be different
type (string or unsigned int), that's why I use 'void*' pointer. But at this
point I faced with the problem of type casting. If I call, for example:
strcpy(conf[5].parameter, "port");
conf[PORT].value = (unsigned short)value;
than get compiler's warning:
config.c:61: warning: cast from pointer to integer of different size
config.c:61: warning: assignment makes pointer from integer without a cast
I'd wish to keep values of different types in my structure. How is better
and correct to fulfil this?
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
Comment