什么是类型? [英] What is a type?
问题描述
我想在C教程的开头添加我写的
关于什么是类型的简短说明是。我提出了以下文字。
请你评论一下吗?
我错过了什么吗?
有什么不对吗在那里?
--------------------------------------- -----------------------------
类型
类型是a存储位序列的定义。它给出了存储在内存中的数据的含义。如果我们说对象a是一个
int,则意味着存储在该位置的位将被理解为
作为由连续添加构建的自然数的权力
两个。如果我们说a的类型是double,则意味着将
的位理解为IEEE 754标准的位序列
表示双精度浮点数点值。
类型可以是基本类型(即内置类型)或复合类型,
即从几种原始类型构建的类型。
函数也有类型。函数的类型由其返回值的
类型及其所有参数确定。函数的类型
是它与外界的接口:它的输入(参数)和它的
输出(返回值)。
C中的类型可能是不完整的,即它们可以作为类型存在但不知道它们的大小和位布局都不知道
。它们对于将数据封装到仅为程序某些部分所知的实体中非常有用。
每种类型都可以有一个关联的指针type:for int我们有int
指针,对于double我们有双指针等等。我们也可以指向一个未指定对象的
指针。它们被写为void
*,即指向void的指针。
lcc-win32中的原始类型是:
类型大小在lcc-win32标准?
bool 1在C99有售
char(签名/未签名)1是
短(签名/未签名) 2是
int(签名/未签名)4是
长(签名/未签名)4是
long long 8适用于C99
浮动4是
双8是
长双12可用于C99
复杂类型16可能缺少某些
实施
qfloat 56具体到lcc-win32
bignum变量具体到lcc-win32
I would like to add at the beginning of the C tutorial I am writing
a short blurb about what "types" are. I came up with the following text.
Please can you comment?
Did I miss something?
Is there something wrong in there?
--------------------------------------------------------------------
Types
A type is a definition for a sequence of storage bits. It gives the
meaning of the data stored in memory. If we say that the object a is an
int, it means that the bits stored at that location are to be understood
as a natural number that is built by consecutive additions of powers of
two. If we say that the type of a is a double, it means that the bits
are to be understood as the IEEE 754 standard sequences of bits
representing a double precision floating point value.
Types can be primitive types (i.e. built-in types) or composite types,
i.e. types built from several primitive types.
Functions have a type too. The type of a function is determined by the
type of its return value, and all its arguments. The type of a function
is its interface with the outside world: its inputs (arguments) and its
outputs (return value).
Types in C can be incomplete, i.e. they can exist as types but nothing
is known about them, neither their size nor their bit-layout. They are
useful for encapsulating data into entities that are known only to
certain parts of the program.
Each type can have an associated pointer type: for int we have int
pointer, for double we have double pointer, etc. We can have also
pointers that point to an unspecified object. They are written as void
*, i.e. pointers to void.
The primitive types in lcc-win32 are:
Type Size in lcc-win32 Standard?
bool 1 Available in C99
char (signed/unsigned) 1 yes
short (signed/unsigned) 2 yes
int (signed/unsigned) 4 yes
long (signed/unsigned) 4 yes
long long 8 Available in C99
float 4 yes
double 8 yes
long double 12 Available in C99
complex types 16 May be absent in some
implementations
qfloat 56 Specific to lcc-win32
bignum variable Specific to lcc-win32
推荐答案
jacob navia写道:
jacob navia wrote:
我想补充一下C教程的开头我正在写一篇关于什么是类型的简短文章。是。
我想出了以下文字。
请你评论一下吗?
" primitive types"和复合类型
看起来类似于术语基本类型和基本类型。和聚合类型。
我认为内置类型,你的意思是基本类型。
目前尚不清楚复合类型是否合适包括工会。
你提到对象类型,不完整的类型和功能类型,
但我会强调这三个主要类别
是类型层次结构中的顶层。
我会说函数类型,
以及由返回类型决定,
由参数确定。而不是参数。
如果函数的参数类型为int,
你可以使用char类型的参数调用它。
我错过了什么吗?
对齐要求根据类型而定。
那里有什么问题吗?
C并不强制要求IEEE浮动点。
-------------------- ------------------------------------------------ <无线电通信/>类型
类型是存储位序列的定义。它给出了存储在内存中的数据的含义。
如果我们说对象a是一个int,那么它意味着要理解存储在该位置的位
作为一个自然数字,由连续增加两个权力构建。如果我们说a的类型是double,那么这意味着将
位理解为表示双精度浮点值的IEEE 754标准位序列。
类型可以是原始类型(即内置类型)或复合类型,即从几种原始类型构建的类型。
函数也有类型。函数的类型由其返回值的
类型及其所有参数决定。
函数的类型
是它与外部世界的接口:它的输入(参数)
及其输出(返回值)。
C中的类型可能不完整,即它们可以作为类型存在但不知道它们的大小和它们的位布局。它们对于将数据封装到仅为程序的某些部分所知的实体非常有用。
每种类型都可以有一个关联的指针类型:对于int我们有int
指针,对于double,我们有双指针等。我们也可以指向指向未指定对象的指针。它们被写为void
*,即指向void的指针。
lcc-win32中的原始类型是:
lcc-win32标准中的类型大小?
bool 1可在C99中使用
char(签名/未签名)1是
短(签名/未签名)2是
int(签名/未签名)4是
长(签名/未签名) 4是
长长8可在C99中使用
浮4是
双8是
长双12可用于C99
复杂类型16可能在某些
实现
qfloat 56具体到lcc-win32
bignum变量具体到lcc-win32
I would like to add at the beginning of the C tutorial I am writing
a short blurb about what "types" are.
I came up with the following text.
Please can you comment?
"primitive types" and "composite types"
seem similar to the terms "basic types" and "aggregate types".
I think by "built-in types", you mean basic types.
It''s not clear whether or not composite types include unions.
You mention object types, incomplete types and function types,
but I would emphasize that those three major catagories
are the top layer in the type hierarchy.
I would say that function types,
as well as being determined by the return type,
are determined by the "parameters" rather than the "arguments".
If a function has a parameter of type int,
you can call it with an argument of type char.
Did I miss something?
Alignment requirements are according to type.
Is there something wrong in there?
C doesn''t mandate IEEE floating point.
--------------------------------------------------------------------
Types
A type is a definition for a sequence of storage bits. It gives the
meaning of the data stored in memory.
If we say that the object a is an int,
it means that the bits stored at that location are to be understood
as a natural number that is built by consecutive additions
of powers of two. If we say that the type of a is a double,
it means that the bits
are to be understood as the IEEE 754 standard sequences of bits
representing a double precision floating point value.
Types can be primitive types (i.e. built-in types) or composite types,
i.e. types built from several primitive types.
Functions have a type too. The type of a function is determined by the
type of its return value, and all its arguments.
The type of a function
is its interface with the outside world: its inputs (arguments)
and its outputs (return value).
Types in C can be incomplete, i.e. they can exist as types but nothing
is known about them, neither their size nor their bit-layout. They are
useful for encapsulating data into entities that are known only to
certain parts of the program.
Each type can have an associated pointer type: for int we have int
pointer, for double we have double pointer, etc. We can have also
pointers that point to an unspecified object. They are written as void
*, i.e. pointers to void.
The primitive types in lcc-win32 are:
Type Size in lcc-win32 Standard?
bool 1 Available in C99
char (signed/unsigned) 1 yes
short (signed/unsigned) 2 yes
int (signed/unsigned) 4 yes
long (signed/unsigned) 4 yes
long long 8 Available in C99
float 4 yes
double 8 yes
long double 12 Available in C99
complex types 16 May be absent in some
implementations
qfloat 56 Specific to lcc-win32
bignum variable Specific to lcc-win32
-
pete
--
pete
pete写道:
jacob navia写道:
jacob navia wrote:
我错过了什么吗?
类型类型是存储位序列的定义。
它给出了存储在内存中的数据的含义。
Did I miss something? Types A type is a definition for a sequence of storage bits.
It gives the meaning of the data stored in memory.
我认为'更接近对象类型的定义。
对象类型也适用于常量表达式。
-
pete
I think that''s closer to the definition of "object type".
Object types also apply to constant expressions.
--
pete
pete写道:
jacob navia写道:
jacob navia wrote:
我错过了什么吗?
对齐要求是根据类型。
Did I miss something?
Alignment requirements are according to type.
我不确定这个应该在教程的开头。当我稍后谈论结构时,我会提到它。
I am not sure that this should be at the beginning of the tutorial. I
mention it when I speak about structures later.
那里有什么问题吗?
C没有要求IEEE浮点。
C doesn''t mandate IEEE floating point.
对。将添加。
Right. Will add that.
这篇关于什么是类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!