数据类型问题 [英] data types question

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

问题描述

仅作为学术兴趣,有没有办法以编程方式

列出c数据类型?我不是在寻找细节,只要它是可能的,并且可以使用什么功能来实现它。例如:


int main void()

{

,而有更多数据类型

{

打印下一个数据类型;

}

返回(0);

}

输出:

int



浮动

char


解决方案

" theshowmecanuck" <双*** @ dev.null>在消息中写道

news:pa **************************** @ dev.null ... < blockquote class =post_quotes>仅作为学术兴趣,有没有办法以编程方式列出c数据类型?我不是在寻找细节,只要它可能,以及可以用什么功能来实现它。例如:

int main void()


int main(void)

{
虽然还有更多数据类型
{
打印下一个数据类型;
}
返回(0);

输出:
int

浮动
char
等。




[推测你排除结构,联合,指针,数组和功能

类型。]


没有这个功能。您可以在C90中编写自己的,因为

有固定数量的基本数据类型。您可以编写一个

程序,该程序在C99下编写程序,假设xxx_leastN_t类型将涵盖任何扩展整数

类型。


那说,你为什么要这样做?即使''学术兴趣''只有

才有用,如果有什么可以从中得到的话。


-

Peter


>>仅作为学术兴趣,有没有办法以编程方式

列出''c''数据类型?我不是在寻找细节,只要它可能,以及可以用什么功能来实现它。例如:



我偶尔会想到将一个type_t数据类型添加到C中,其中
包含某种类型的东西,可以用来运行-time

数据输入(除此之外,您可以将某些内容转换为由type_t变量指定的类型

)。问题:它需要多少位?

[推测你排除了struct,union,pointer,array和function
类型。]


我不排除那些类型,而int [2] [3] [4] [5] [6]是与b [3] [2] [4]不同的
] [5] [6]。这样的事情使得

type_t更加不切实际。

没有这样做的功能。您可以在C90中编写自己的,因为
有固定数量的基本数据类型。您可以编写一个在C99下编写程序的程序,假设xxx_leastN_t类型下将包含任何扩展的整数类型。




由于C没有对指向指针的指针的间接级别的最大数量(对于$
变量)进行任何上限,所以'''''''''''''''''''''''''''''''''''''''''''''''一个真正的问题,程序永远不会终止。

另一个与我的type_t想法有关的挑战:给定一系列函数

在type_t上运行,例如type_is_array(), type_is_function(),

type_is_pointer(),它告诉你一个类型的特征,并且

类型为type_dereference()的一些运算符,它返回
当你取消引用它的参数时得到
类型,而type_elementtype(),

返回数组类型元素的类型,写一个程序

哪个使用提供的v打印出该类型的C声明ariable

name和type_t。


您可能会看到这样的代码只有一个简单的版本,只需要担心基本担心数据类型和指向它们的指针(不是数组,

函数,结构,联合等):


for(t = value; type_is_pointer(T); t = type_dereference(t)){

printf(" *");

}


Gordon L. Burditt


Gordon Burditt写道:

仅作为学术兴趣,有没有办法以编程方式列出''c''数据类型?我不是在寻找细节,只要它可能,以及可以用什么功能来实现它。例如:



我偶尔会想到将一个type_t数据类型添加到C中,其中包含某种类型的东西,可以用来运行-time
数据输入(除此之外,您可以将某些内容转换为由type_t变量指定的类型)。问题:它需要多少位?



恕我直言,它必须是可变长度的,你必须为它创造一些编码

to能够获得读取字符流的类型。 (所以前例。

type_t必须是typedefed作为char的指针)。

另一个问题是你为什么要列出所有类型。我认为

唯一使用的type_t对象是将它设置为另一个现有对象的类型。铸造到明确定义的类型已经实现了b $ b。铸造到一些随机类型是没有用的。


-

vir


As a matter of academic interest only, is there a way to programmatically
list the ''c'' data types? I am not looking for detail, just if it is
possible, and what function could be used to accomplish it. For example:

int main void()
{
while there are more data types
{
print next data type;
}
return(0);
}
output:
int
long
float
char
etc.

解决方案

"theshowmecanuck" <bi***@dev.null> wrote in message
news:pa****************************@dev.null...

As a matter of academic interest only, is there a way to programmatically
list the ''c'' data types? I am not looking for detail, just if it is
possible, and what function could be used to accomplish it. For example:

int main void()
int main(void)
{
while there are more data types
{
print next data type;
}
return(0);
}

output:
int
long
float
char
etc.



[Presumably you''re ruling out struct, union, pointer, array and function
types.]

There is no function to do this. You could write your own in C90, since
there are a fixed number of basic data types. You could probably write a
program which writes a program under C99, assuming any extended integer
types will be covered under the xxx_leastN_t types.

That said, why would you want to do this? Even ''academic interest'' is only
useful if there''s something to be derived from it.

--
Peter


>> As a matter of academic interest only, is there a way to programmatically

list the ''c'' data types? I am not looking for detail, just if it is
possible, and what function could be used to accomplish it. For example:


I have occasionally thought about adding a type_t data type to C, which
contains the type of something, and could be used to do run-time
data typing (among other things, you could cast something to a type
specified by a type_t variable). Question: how many bits does it need?
[Presumably you''re ruling out struct, union, pointer, array and function
types.]
I''m not ruling out those types, and int [2][3][4][5][6] is
different from int [3][2][4][5][6]. It''s things like this that make
type_t more than a bit impractical.
There is no function to do this. You could write your own in C90, since
there are a fixed number of basic data types. You could probably write a
program which writes a program under C99, assuming any extended integer
types will be covered under the xxx_leastN_t types.



Since C does not place any upper limit on things like the maximum number
of levels of indirection on pointer to pointer to pointer ... to char
variables, there''s a real problem the program would never terminate.
Another challenge related to my type_t idea: given a series of functions
that operate on a type_t, such as type_is_array(), type_is_function(),
type_is_pointer(), which tell you the characteristics of a type, and
some operators on types like type_dereference(), which returns the
type you get when you dereference its argument, and type_elementtype(),
which returns the type of the elements of an array type, write a program
which prints out a C declaration for that type, using a supplied variable
name and type_t.

You might see code like this in a simplified version that only had
to worry about basic data types and pointers to them (not arrays,
functions, structs, unions, etc.):

for (t = value; type_is_pointer(t); t = type_dereference(t)) {
printf("*");
}

Gordon L. Burditt


Gordon Burditt wrote:

As a matter of academic interest only, is there a way to programmatically
list the ''c'' data types? I am not looking for detail, just if it is
possible, and what function could be used to accomplish it. For example:


I have occasionally thought about adding a type_t data type to C, which
contains the type of something, and could be used to do run-time
data typing (among other things, you could cast something to a type
specified by a type_t variable). Question: how many bits does it need?


IMHO, it must be of variable length, you must invent some coding for it
to be able to get the type reading the stream of chars. (so fo ex.
type_t must be typedefed as pointer to char).
The other question is why do you want to list all types. I think that
the only use of type_t object is to set it to the type of the other
existing object. Casting to the explicitely defined type is allready
implemented. Casting to some random type is of no use.

--
vir


这篇关于数据类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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