在C中获取变量类型 [英] getting variable type in C

查看:68
本文介绍了在C中获取变量类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我很确定这是不可能的,但也许不知何故。


鉴于变量,我可以告诉它在运行时的类型是什么?


Michael

Hi,

I am pretty sure this is not possible, but maybe somehow it is.

Given a variable, can I tell what type it is at runtime?

Michael

推荐答案



在2004年11月13日星期六,Michael McGarry写道:

On Sat, 13 Nov 2004, Michael McGarry wrote:

给定一个变量,我可以告诉它在运行时的类型吗?

Given a variable, can I tell what type it is at runtime?




当然。只需在编译时获取它的类型,并记住它。

例如,


int main(无效)

{

int i;

printf(我的类型为%s。\ n," int);

返回0;

}


如果您有其他想法,那么您将需要更多

明确。


-Arthur



Sure. Just take the type it was at compile time, and remember it.
For example,

int main(void)
{
int i;
printf("i is of type %s.\n", "int");
return 0;
}

If you have some other idea in mind, you''re going to have to be more
explicit.

-Arthur


On Sun,2004年11月14日04:28:36 UTC,Michael McGarry
< mm ****** @ nospam.org>写道:
On Sun, 14 Nov 2004 04:28:36 UTC, Michael McGarry
<mm******@nospam.org> wrote:


我很确定这是不可能的,但也许不知何故。

给定一个变量,我可以告诉它在运行时的类型吗?
Hi,

I am pretty sure this is not possible, but maybe somehow it is.

Given a variable, can I tell what type it is at runtime?




编号您的编译器用地址替换名称。没有什么比人类更好的了写作的元素需要变量的名称,所以编译器

消除它们。


-

Tschau / Bye

Herbert


访问 http://www.ecomstation.de 德国eComStation的主页



No. Your compiler replaces names with addresses. Nothing as the human
writing the souerces needs names for variables, so the compiler
eliminates them.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation




Michael McGarry <毫米****** @ nospam.org>在消息新闻中写道:T9Bld.58779

"Michael McGarry" <mm******@nospam.org> wrote in message news:T9Bld.58779


这篇关于在C中获取变量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆