对象和表达 - 挑剔的问题 [英] Objects and expressions - nitpicky questions

查看:49
本文介绍了对象和表达 - 挑剔的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

===========

(N869,p8)对象是执行

环境中的数据存储区域,内容其中可以代表价值观。


在向学生解释这个问题时,是否合理地说

类似于:


从实际的角度来看,对象是具有

地址的东西 - 可以计算的地址。这不是
必然意味着我们可以读写该对象 -

我们可以做一个,另一个或两者(如果我们不能这样做,或者是b $ b,这是毫无意义的。


所以字符串文字就是一个对象。

你的程序正在运行时它就在内存中。我们可以确定它的地址。我们

可以从中读取。我们不应该写它(这样做会调用

未定义的行为)。


但是一个数值常数,例如
中的3

y = x + 3;


不是对象。它不是(至少不保证)在特定的数据存储区域。它很可能是嵌入在指令的操作码中的值

。试图计算3的

地址将调用未定义的行为。

最后一句,关于其中的内容可代表

值 ;。这基本上是修辞的,或者对于对象的

定义很重要。问另一种方式,在执行环境中只是说一个对象是数据区域的存储是不正确的?
是不正确的?什么东西(值得

做出区分)会不会包含那些在实际定义下作为对象包含的


== =========

(N869,p68 - 子条款6.5)表达式是

运算符和操作数的序列,用于指定计算一个值,或

指定一个对象或一个函数,或者生成一个

效果,或者执行它们的组合。


那么只是一个常数呢?


行:


32;


什么都不做,但这是一种法律表达,对吧?然而它不是操作数
(因为没有运算符),它不是运算符,

它既不表示对象也不表示函数,并且它不生成

副作用。所以,从技术上讲,这不是一个表达,对吗?


但是下一个子条款6.5.1,具体说明了一个

标识符(提供它表示一个对象或函数),一个

常量,一个字符串文字(表示一个对象),一个

括号表达式都是主表达式。这与

协议有一个表达式的基本定义,除了

常量的情况。


这是一个

表达式的基本定义中的微妙疏忽?或者我只是不读正确的东西?


===========
(N869, p8) An object is a region of data storage in the execution
environment, the contents of which can represent values.

When explaining this to students, is it reasonable to say
something like:

From a practical standpoint, objects are things that have
addresses - addresses that can be computed. This doesn''t
necessarily mean that we can both read and write to that object -
we may be able to do one, the other, or both (if we can''t do
either, it''s rather pointless).

So a string literal is an object. It is sitting in memory when
your program is running. We can determine the address of it. We
can read from it. We shouldn''t write to it (doing so invokes
undefined behavior).

But a numerical constant, such as the 3 in

y = x + 3;

is not an object. It is not (at least not guaranteed to be) at a
particular region of data storage. It is very possibly a value
embedded in an instruction''s op code. Trying to compute the
address of 3 will invoke undefined behavior.
That last clause, about "the contents of which can represent
values". Is that basically rhetorical or it is important to the
definition of an object. Asked another way, what would be
incorrect about just saying that an object is a region of data
storage in the execution environment? What things (worthy of
making the distinction) would that include that would not be
included as objects under the actual definition?
===========

(N869, p68 - subclause 6.5) An expression is a sequence of
operators and operands that specifies computation of a value, or
that designates an object or a function, or that generates side
effects, or that performs a combination thereof.

So what about just a constant?

The line:

32;

Does nothing, but it''s a legal expression, right? Yet is it not
an operand (since there is not operator), it is not an operator,
it denotes neither an object nor a function, and it generates no
side effects. So, technically, this isn''t an expression, correct?

But the next subclause, 6.5.1, specifically says that an
identifier (provided it denotes an object or a function), a
constant, a string literal (which denotes an object), and a
parenthesized expression are all primary expressions. This is in
agreement with the basic definition of an expression except for
the case of a constant.

Is this a subtle oversight in the basic definition of an
expression? Or am I just not reading something right?



推荐答案

William L. Bahn写道:
William L. Bahn writes:
(N869,p8)对象是执行
环境中的数据存储区域,其内容可以表示值。

解释时这对学生说,是否合理如下:
(N869, p8) An object is a region of data storage in the execution
environment, the contents of which can represent values.

When explaining this to students, is it reasonable to say
something like:




我认为C中的教师应该避免使用对象这个词。 br />
由于这个词在不同的语境中有不同的含义,只有一种语言

律师应该在C语境中使用这个词。语言律师

发展自己,他们不是学生普遍接受的意思

的学生。有足够的其他词语,所以这个可以避免,

例如:l值,r值;我无法想象一个普通

学生必须被告知C对象是什么的情况。


如果学生特别要求,那么应该教练的回答是,

这是一个令人讨厌的,令人讨厌的词,比如堆栈。或moot,然后

详细说明。



I think an instructor in C should simply avoid using the word "object".
Since the word has different meanings in different contexts only a language
lawyer should need to use this word in the context of C. Language lawyers
develop themselves, they aren''t students in the generally accepted meaning
of "student". There are enough other words so this one can be avoided,
example: l value, r value; I can''t imagine a situation where an ordinary
student must be told what a C object is.

If a student specifically asks, only then should the instructor answer that
it is one of those nasty, annoying words like "stack" or "moot", and then
elaborate.


" William L. Bahn"写道:
"William L. Bahn" wrote:

(N869,p8)对象是执行
环境中的数据存储区域,其内容可以表示值。

(N869, p8) An object is a region of data storage in the execution
environment, the contents of which can represent values.




这恰好是3.15节。部分编号不受

实际分页的影响,实际分页可能会有所不同,因此最好在

引用参考文献中使用它们。


-

答:因为它会破坏人们通常阅读文本的顺序。

问:为什么顶级发布这么糟糕的事情?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



This happens to be section 3.15. The section number is immune to
actual pagination, which can vary, so it is better to use them in
citing references.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


" ; William L. Bahn <无线***** @ toomuchspam.net>写道:

[...]
"William L. Bahn" <wi*****@toomuchspam.net> writes:
[...]
但是一个数值常数,例如
中的3 = y + x + 3;

不是一个对象。它不是(至少不保证)在特定的数据存储区域。它很可能是嵌入在指令的操作码中的值。尝试计算3的地址将调用未定义的行为。


尝试计算3(& 3)的地址并不会调用未定义的

行为;这是一个需要诊断的约束违规,因为

3不是左值。


(现在在comp.std中有讨论) .c关于C99标准''
的定义左值。通过字面读取定义,3是左值和可修改左值的
。但它普遍同意

,这至少是标准措辞中的一个缺陷.3真的

不是一个左值;辩论是否标准正确

表达了这一事实。)


[...](N869,p68 - 子条款6.5)表达式是一个序列
运算符和操作数,用于指定值的计算,或指定对象或函数,或生成副作用或执行其组合的操作和操作数。

这句话:

32;

什么都不做,但这是一个法律表达,对吧?但它不是一个操作数(因为没有操作符),它不是一个操作符,它既不是一个对象也不是一个函数,它不会产生副作用。所以,从技术上讲,这不是一个表达,对吗?

但是下一个子条款6.5.1特别指出了一个
标识符(假设它表示一个对象或一个函数) ,
常量,字符串文字(表示对象),
括号表达式都是主表达式。这与表达式的基本定义是一致的,除了
常量的情况。

这是否是对基本定义的一个微妙的疏忽
表达?或者我只是不读正确的东西?
But a numerical constant, such as the 3 in

y = x + 3;

is not an object. It is not (at least not guaranteed to be) at a
particular region of data storage. It is very possibly a value
embedded in an instruction''s op code. Trying to compute the
address of 3 will invoke undefined behavior.
Trying to compute the address of 3 (&3) doesn''t invoke undefined
behavior; it''s a constraint violation requiring a diagnostic, because
3 isn''t an lvalue.

(There''s a discussion now in comp.std.c about the C99 standard''s
definition of "lvalue". By a literal reading of the definition, 3 is
both an lvalue and a modifiable lvalue. But it''s universally agreed
that that''s at most a flaw in the wording of the standard. 3 really
isn''t an lvalue; the debate is over whether the standard correctly
expresses that fact.)

[...] (N869, p68 - subclause 6.5) An expression is a sequence of
operators and operands that specifies computation of a value, or
that designates an object or a function, or that generates side
effects, or that performs a combination thereof.

So what about just a constant?

The line:

32;

Does nothing, but it''s a legal expression, right? Yet is it not
an operand (since there is not operator), it is not an operator,
it denotes neither an object nor a function, and it generates no
side effects. So, technically, this isn''t an expression, correct?

But the next subclause, 6.5.1, specifically says that an
identifier (provided it denotes an object or a function), a
constant, a string literal (which denotes an object), and a
parenthesized expression are all primary expressions. This is in
agreement with the basic definition of an expression except for
the case of a constant.

Is this a subtle oversight in the basic definition of an
expression? Or am I just not reading something right?




在我看来,这是对

表达式基本定义的微妙疏忽。在我看来(这是

comp.std.c中讨论的一部分),标准第3节中的定义是

相当不错的,但是一些定义通过

散布在标准文本中,其中定义的术语为斜体类型,

不完整。在我看来,其中一些是关于定义的术语

的陈述,但实际上并不是该术语的定义。 (参见

"表达式"和左值。)


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



In my opinion, it''s subtle oversight in the basic definition of an
expression. In my opinion (and this is part of the discussion over in
comp.std.c), the definitions in section 3 of the standard are
reasonably good ones, but some of the definitions scattered through
the text of the standard, with the defined term in italic type, are
incomplete. Some of them seem to me to be statements about the term
being defined, but not actually definitions of the term. (See
"expression" and "lvalue".)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于对象和表达 - 挑剔的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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