一些问题#2 [英] Some Questions #2

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

问题描述

其他一些疑问:


1)K& R,p50,2.10:


"如果expr1和expr2是表达式,然后

expr1 op = expr2

相当于

expr1 =(expr1)op(expr2)

除外expr1只计算一次。


什么做除了expr1只计算一次意思?你可以在这个适当的例子中做出什么吗?


2)字符常量的值如'C'是真的吗? '取决于系统字符集(ASCII,EBCDIC,......)上的
?所以,如果我用'C'来写
,那么我的程序是否会变得不便携?


3)这是真的吗?必须*是1个字节?而是
http:// www-ccs.ucsd.edu/c/types.html...nteger%20Types 写成

必须是无符号字符的* minimum *范围,用于

例子,必须是0到255,所以它可能是2个字节或200个字节

没有任何问题。


4)我在区分声明与定义方面存在一些问题。


例如:


双重函数(双x,双y); / * prototype(一种函数

声明)* /


双重函数(双x,双y){/ *函数定义* /


int a; / *定义?宣言? * /


}


也是,在函数定义中是''双x,双y''

定义或两个声明?


谢谢。

解决方案

fctk写道:

其他一些疑问:

1)K& R,p50,2.10:

如果expr1和expr2是表达式,那么
expr1 op = expr2
相当于
expr1 =(expr1)op(expr2)
除了expr1只计算一次。

什么做除了expr1只计算一次意思?你能说出这个礼仪重要的例子吗?

很难说。在两种情况下,expr1的值只计算一次。

2)字符常量(如C)的值是否依赖于系统字符集( ASCII,EBCDIC,...)?所以,如果我写的是''C'' - 20,我的程序会变得不便携吗?

不一定。这取决于你对结果的处理方式。

3)char *必须是1个字节才是真的吗?而是
http:// www-ccs.ucsd.edu/c/types.html...nteger%20Types 写的
必须是unsigned char的* minimum *范围,例如,
必须从0到255,所以它可能是2个字节或200个字节
没有任何问题。

是的。术语char和byte通常是可以互换的。

''sizeof(char)''是有保证的。

4)我在区分声明与定义方面存在一些问题。

例如:

双功能(双x,双y); / * prototype(一种函数
声明)* /

双函数(double x,double y){/ *函数定义* /

int a ; / *定义?宣言? * /

}
你有两个正确的。
也是,''x,双y'在函数定义中两个
定义或两个声明?

声明向编译器提供信息,而不会影响内存(存储)。函数原型是声明。


定义也是一个声明(编译器的信息),但是它需要在内存中为自己提供空间。

谢谢。



-

Joe Wright

所有东西都应该尽可能简单,但是并不简单。

---阿尔伯特爱因斯坦---





fctk写道在04/14/06 13:21,:

其他一些疑问:

1)K& R,p50,2.10:

;如果expr1和expr2是表达式,那么
expr1 op = expr2
等同于
expr1 =(expr1)op(expr2)
除了expr1只计算一次。 ;

什么是除了expr1只计算一次意思?你能说出这个礼仪重要的例子吗?


数组[expensive_function(x)] + = 1;


如果计算不是

总是返回相同的答案:


数组[getchar()] + = 1;

2)是真的,它的值是诸如C之类的字符常量取决于系统字符集(ASCII,EBCDIC,...)?所以,如果我写的是''C'' - 20,我的程序会变得不便携吗?


是的,C的数值确实取决于

字符编码。是的,确实,你所展示的那种算术会产生一个结果,其含义将因实现而异。 (例外:数字的代码

必须是连续的并且按升序排列,所以

''0''+ 1 ==''1'',.. 。,''8''+ 1 ==''9''。但是,''a''+ 1 ==''b''不是保证
。)

3)char *必须*是1个字节吗?而是
http:// www-ccs.ucsd.edu/c/types.html...nteger%20Types 写的
必须是unsigned char的* minimum *范围,例如,
必须从0到255,所以它可能是2个字节或200个字节
没有任何问题。


在C中,一个字节被定义为char的同义词。一些

其他字段使用术语字节 存储单元是指包括8位的存储单元,b $ b。但是C没有:在C中,无论字符有多宽,一个字节都是char




这与你面临的情况完全相同在

理解其他词语:不同的话语使用领域

具有不同含义的同一个词,你必须知道

上下文才能找到正确的意思。例如,考虑

各种含义文件。如果你在谈论


- 如何使用fopen()函数


- 游行乐队展示的阵型


- 金属工的工具箱内容


- 来自Cajun食谱的食谱(好吧,发音

可能会提示你关于这一个)

4)我在区分声明与定义方面存在一些问题。

例如:

双重功能(双x,双y); / * prototype(一种函数
声明)* /

双函数(double x,double y){/ *函数定义* /

int a ; / *定义?宣言? * /

}


声明描述了对象或函数的类型

标识符指定。定义还带来了

对象或函数,为
对象分配存储或为函数提供可执行代码。

每个定义都是也是一个声明,但声明

不一定是定义。当我说fctk是一个C&B的学生b $时我做了一个关于fctk的声明。意思是;

a定义更像是fctk是C的学生,而这里是

他是(微笑,fctk,微笑和波浪)。


原型是函数参数的描述。

原型可能作为函数声明的一部分出现,或者

as函数定义的一部分,但原型只是关于参数列表的部分。你的第一个例子是使用原型的

函数声明;你的第二个是使用原型的

函数定义。它们中的任何一个都不是原样的原型。

也是,在功能定义中有两倍的双y定义两个
定义或两个声明?




从形式上讲,它们是声明。请注意,装饰的一些

。有定义的可能是函数参数不可能是
;这些都是非法的:


双f(静态双x,外部双y,

双z = 42.0,typedef双重麻烦)


函数参数不需要定义;如果你想要
,你可以认为它们是定义的作为

调用函数的过程的一部分。不知怎的,编译器

导致参数出现并被初始化

,参数值作为函数调用的一部分,

和某种方式当

函数返回时,编译器会使它们再次消失。如果您对编译器和

相关工具的工作方式感兴趣,那么这种推理的机制对您来说非常重要。如果你只需要使用C,它们就不是。


-
Er ********* @ sun.com


2006年4月14日星期五19:21: 37 +0200,在comp.lang.c中,fctk< - >写道:

什么做除了expr1只计算一次意思?你能说出这个礼仪重要的例子吗?


如果expr1是重要的话。每次调用它时都会改变,因为

例子x ++

2)字符常量的值如C是否正确
在系统字符集(ASCII,EBCDIC,...)?所以,如果我写的是''C'' - 20,我的程序会变得不便携吗?


是的。

3)char *必须*是1字节是真的吗?


是的。这是C中字节的定义。

而是
http://www-ccs.ucsd.edu/c/types.html...gerger%20Types 写的是必备的对于
示例,无符号字符的* minimum *范围必须是0到255,所以它可能是2个字节或200个字节
没有任何问题。


真正的最小范围必须是0-255,但是这个onl定义了最小的比特数b $ b。 字节是指字节。在C中定义的数字与字符中的数字

一样大,即使它是8,9,32或36.

4)我有一些区分声明和定义的问题。


声明没有定义。如果语句要么设置

的值,要么包含代码,那么它的定义是



也是, ''double x,double y''在函数定义中有两个
定义或两个声明?




在一个声明中,它们都不是(因为你可以把它们排除在外它

没有任何区别。)

在函数定义中,它们是参数的声明。

马克麦金太尔

-

调试是首先编写代码的两倍。

因此,如果您尽可能巧妙地编写代码,那么,根据定义,它不够聪明,无法调试它。

--Brian Kernighan


some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?

2) is it true that the value of a character constant such as ''C'' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as ''C'' - 20, will my program become not portable?

3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.

4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

}

also, are ''double x, double y'' in the function definition two
definitions or two declarations?

thanks.

解决方案

fctk wrote:

some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
Hard to say. The value of expr1 is computed only once in both cases.
2) is it true that the value of a character constant such as ''C'' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as ''C'' - 20, will my program become not portable?
Not necessarily. It depends on what you do with the result.
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.
Yes. The terms char and byte are generally interchangeable and
''sizeof(char)'' is guaranteed 1.
4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

} You''ve got those two right.
also, are ''double x, double y'' in the function definition two
definitions or two declarations?
A declaration presents information to the compiler without affecting
memory (storage) at all. Function prototypes are declarations.

A definition is also a declaration (info for the compiler) but it
demands space for itself in memory.
thanks.


--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---




fctk wrote On 04/14/06 13:21,:

some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
array[ expensive_function(x) ] += 1;

It becomes even more important if the computation doesn''t
always return the same answer:

array[ getchar() ] += 1;
2) is it true that the value of a character constant such as ''C'' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as ''C'' - 20, will my program become not portable?
Yes, it is true that the numeric value of ''C'' depends on
the character encoding. Yes, it is true that doing arithmetic
of the kind you''ve shown produces a result whose meaning will
vary from one implementation to another. (Exception: the codes
for the digits must be consecutive and in ascending order, so
''0''+1 == ''1'', ..., ''8''+1 == ''9''. However, ''a''+1 == ''b'' is not
guaranteed.)
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.
In C, a byte is defined as synonymous with a char. Some
other fields use the term "byte" to mean "a unit of storage
comprising eight bits," but C does not: in C, a byte is a char
no matter how wide a char is.

This is really the same situation that confronts you in
understanding other words: Different realms of discourse use
the same word with different meanings, and you must know the
context to find the proper meaning. For example, consider the
various meanings "file" might have if you''re talking about

- how to use the fopen() function

- the formations exhibited by a marching band

- the contents of a metalworker''s toolbox

- recipes from a Cajun cookbook (well, the pronunciation
might tip you off about this one)
4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

}
A declaration describes the type of object or function
an identifier designates. A definition also brings the
object or function into existence, allocating storage for
objects or providing the executable code for functions.
Every definition is also a declaration, but a declaration
is not necessarily a definition. When I say "fctk is a
student of C" I make a declaration about what "fctk" means;
a definition is more like "fctk is a student of C, and here
he is (smile, fctk, smile and wave)."

A prototype is a description of a function''s parameters.
A prototype may appear as part of a function declaration or
as part of a function definition, but the prototype is only
the part about the parameter list. Your first example is a
function declaration using a prototype; your second is a
function definition using a prototype. Neither of them "is"
a prototype in its entirety.
also, are ''double x, double y'' in the function definition two
definitions or two declarations?



Formally speaking, they are declarations. Note that some
of the "decorations" that are possible with definitions are
not possible with function parameters; these are illegal:

double f(static double x, extern double y,
double z = 42.0, typedef double trouble)

Function parameters don''t need definitions as such; if you
want, you can think of them as being "defined" as part of
the process of calling the function. Somehow the compiler
causes the parameters to come into existence and be initialized
with the argument values as part of the function invocation,
and somehow the compiler causes them to vanish again when the
function returns. If you are interested in how compilers and
related tools work, the mechanics of this buck-passing are of
importance to you; if you simply need to use C, they are not.

--
Er*********@sun.com


On Fri, 14 Apr 2006 19:21:37 +0200, in comp.lang.c , fctk <-> wrote:

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
it would be important if "expr1" changed each time you invoked it, for
example x++
2) is it true that the value of a character constant such as ''C'' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as ''C'' - 20, will my program become not portable?
Yes.
3) is it true that a char *must* be 1 byte?
Yes. This is the definition of a byte in C.
here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.
Its true the min range must be 0-255, but this onl defines the minimum
number of bits. A "byte" is defined in C to be as large as the number
of bits in a character, even if that is 8, 9, 32 or 36.
4) i have some problems at distinguish declaration from definitions.
A declaration doesn''t define something. If the statement either sets
the value of something, or contains code which will do so, then its a
definition.
also, are ''double x, double y'' in the function definition two
definitions or two declarations?



In a declaration, they''re neither (since you can leave them out and it
doesn''t make any difference).
In a function definition, they''re declarations of the parameters.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan


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

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