运行时确定类型对于C [英] runtime determine type for C
问题描述
如果一个变量的类型必须确定为C运行时,但变量名是固定的,给予,是有什么办法可以重新使用code,涉及的变量?
If the type of a variable must be determined as runtime in C but the variable name is fixed and given, is there any way to reuse the code that involves the variable?
其实我问的运行的C语言的情况确定类型C ++
如果可能,请举一些例子。
If possible please give some examples.
推荐答案
C语言不具有面向对象的特性,使得它有意义请教一下在C ++中对象的运行时类型。
The C language does not have the object-oriented features that make it meaningful to ask about the run-time type of an object in C++.
您通常通过铸造和里用C实现泛型的void *
。例如: C函数的qsort
You typically implement genericity in C by casting to and from void*
. Example: the C function qsort.
如果你的问题是关于在运行时什么实际类型无效*
指针指向,这是不可能的决定。这些信息根本就没有被大多数编译器保存的。
If your question is about determining at run-time what actual type a void*
pointer points to, that's impossible. The information is simply not stored at all by most compilers.
这篇关于运行时确定类型对于C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!