【发布时间】:2014-01-16 18:59:08
【问题描述】:
我试图将作为命令行参数给出的数据类型保存在我的 C 程序中,并在整个程序中使用该类型而不检查它。例如,我可以运行程序“./name -d int”或“./name -d float”,我希望保存数据类型以供进一步使用并在整个程序中看到,而不仅仅是在主功能。一个简短的例子:
int main() {
/* read command line argument */
/* I would like to be able to save the type in T to use like this */
T a[20];
/* rest of the program */
}
我可以这样做吗?
谢谢。
【问题讨论】:
-
不,你不能。在编译时检查类型。你不能在运行时声明它们。