C言語なら俺に聞け<35>
■ このスレッドは過去ログ倉庫に格納されています
0544デフォルトの名無しさん
NGNGstruct variable_info {
const char *name;
int type;
void *ptr;
};
#define TYPE_INT0
#define TYPE_DOUBLE1
/* 二分探索を行うために変数名でソートされた配列 */
static struct variable_info variables[] = {
{ "bar", TYPE_INT, &bar },
{ "hoge", TYPE_DOUBLE, &hoge },
...
};
static struct variable_info *
get_variable_info(const char *name) {
/* 二分探索を実装 */
}
void set_variable_int(const char *name, int value) {
struct variable_info *info = get_variable_info(name);
if (info->type == TYPE_INT) {
*((int *)info->ptr) = value;
} else if (info->type == TYPE_DOUBLE) {
*((double *)info->ptr) = value;
}
}
■ このスレッドは過去ログ倉庫に格納されています