从Variable输入名称 [英] Type name from Variable

查看:64
本文介绍了从Variable输入名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我想打印一些变量的数据类型名称...

有一个名为typeof(var)的函数返回var的数据类型

但是想打印它所以我需要char *格式的结果

有什么方法吗?


请帮帮我

Hi friends,
I want to print data type name of some variables...
there is a function called typeof(var) which returns data type of var
but want to print it so i need the result in char* format
is there any method for that??

Please help me out

推荐答案

2007年3月28日00:25:07 -0700,ro ****** **@gmail.com"

< ro ******** @ gmail.comwrote:
On 28 Mar 2007 00:25:07 -0700, "ro********@gmail.com"
<ro********@gmail.comwrote:

> Hi朋友,
我想打印一些变量的数据类型名称...
有一个名为typeof(var)的函数返回var
的数据类型但是想打印它所以我需要char *格式的结果
是否有任何方法?
>Hi friends,
I want to print data type name of some variables...
there is a function called typeof(var) which returns data type of var
but want to print it so i need the result in char* format
is there any method for that??



在标准C中无法做到这一点.gcc将此作为

扩展实现,但即便如此,我也不会我认为它可以满足您的需求。


如果您可以从typeof打印出您想要的内容,那么您肯定必须

才能访问和能够修改源代码。如果是这样,为什么在

地球上你想要打印出变量的类型?当然

源代码毫不含糊地告诉你这是什么类型。在C语言中,与其他一些语言中的
不同,对象的真实类型总是在

编译时知道。


如果你能提供更多关于你想要完成的事情的细节,或许我们可以给你一些好的建议。

最好的问候

- -

jay

There is no way to do this in Standard C. gcc implements this as an
extension, but even at that, I don''t think it does what you want.

If you can print what you desire from "typeof", then surely you must
have access to and are able to modify the source code. If so, why on
Earth would you want to print out the type of a variable? Certainly
the source code tells you unambiguously what the type is. In C, unlike
in some other languages, the true type of an object is always known at
compile time.

If you could provide more details on what you are trying to
accomplish, perhaps we could give you some good advice.
Best regards
--
jay


实际上我正在尝试编写一个预处理器,

在那个预处理器中我用一个替换任何一个赋值宏的哪个

将分配记录在一个日志文件中..


为了记录目的,我需要知道rvalue的类型n

lvalue ..

任何解决方案?

Actually i m trying to write a preprocessor,
In that preprocessor i m replacing any assignment with a macro which
logs the assignment in a logfile..

in that for logging purpose, i need to know the type of rvalue n
lvalue..
any solution for this??


" ro ******** @ gmail.com" < ro ******** @ gmail.comwrote:

#嗨朋友们,

#我想打印一些变量的数据类型名称...

#有一个名为typeof(var)的函数,它返回var的数据类型
#但是想打印它所以我需要char *格式的结果

#有什么办法吗?


没有ANSI C解决方案,也没有极少数非标准解决方案。

Objective-C确实有这个扩展作为他们的@-thingies之一。


-

SM Ryan http://www.rawbw.com/~wyrmwif/

你还没有听说过客户永远是对的吗?
"ro********@gmail.com" <ro********@gmail.comwrote:
# Hi friends,
# I want to print data type name of some variables...
# there is a function called typeof(var) which returns data type of var
# but want to print it so i need the result in char* format
# is there any method for that??

There is no ANSI C solution, and precious few nonstandard solutions.
Objective-C does have this extension as one of their @-thingies.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Haven''t you ever heard the customer is always right?


这篇关于从Variable输入名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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