一些问题#2

扫码查看
本文介绍了一些问题#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个字节?而是
写成

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

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

没有任何问题。


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


例如:


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

声明)* /


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


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


}


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

定义或两个声明?


谢谢。

解决方案



-

Joe Wright

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

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





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

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


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

双z = 42.0,typedef双重麻烦)


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

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

导致参数出现并被初始化

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

和某种方式当

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

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


-






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

没有任何区别。)

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

马克麦金太尔

-

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

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

--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.

解决方案


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




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




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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 18:39
查看更多