悬垂指针测验问题 [英] Dangling pointer quiz question

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

问题描述

大家好。


测验中我有一个关于悬挂指针的问题:

多么悬垂的指针和使用它的危险


我的回答是:

"悬空指针是一个指向某个ram区域的指针'

不是由程序保留。通过这样的指针访问内存是

可能导致核心转储(内存访问违规)


这是10-中的两个问题之一min quiz(我迟了5分钟

这个测验:)


这个问题基于3标记,我得到2这个问题和

更正是悬空的prt是指向..指向无效

内存的指针。请问3/3我的答案是否合理?


第二个问题我得到2/7,但我会解决这个问题 - 那里

我100%肯定它一定是7/7 ......

Hello everybody

in a quiz I had a question about dangling pointer:
"What a dangling pointer is and the danger of using it"

My answer was:
"dangling pointer is a pointer that points to some area of ram that''s
not reserved by the program. Accessing memory through such pointer is
likely to result in core dump (memory access violation)"

This was one of the two questions in a 10-min quiz (I was 5 mins late
for this quiz :)

This question is marked based on 3, I got 2 for this question and
correction was that dangling prt is pointer that "..points to invalid
memory". Is this reasonable to ask for 3/3 for my answer?

I got 2/7 for the second question, but I''ll fix that problem - there
I''m 100% sure it must be 7/7 ...

推荐答案

文章< 11 * *********************@g14g2000cwa.googlegroups .com> ;,

__PPS__< i - ******** *@yandex.ru>写道:
In article <11**********************@g14g2000cwa.googlegroups .com>,
__PPS__ <i-*********@yandex.ru> wrote:
在测验中我有一个关于悬挂指针的问题:
多么悬垂的指针和使用它的危险

我的回答是:
悬挂指针是一个指向某个ram区域的指针,它不是程序保留的。通过这样的指针访问内存可能会导致核心转储(内存访问违规)

这是10分钟测验中的两个问题之一(我迟到了5分钟)
这个测验:)

这个问题基于3标记,我得到2这个问题和
纠正是悬挂prt指针..指向无效的内存请问3/3我的答案是否合理?
in a quiz I had a question about dangling pointer:
"What a dangling pointer is and the danger of using it"

My answer was:
"dangling pointer is a pointer that points to some area of ram that''s
not reserved by the program. Accessing memory through such pointer is
likely to result in core dump (memory access violation)"

This was one of the two questions in a 10-min quiz (I was 5 mins late
for this quiz :)

This question is marked based on 3, I got 2 for this question and
correction was that dangling prt is pointer that "..points to invalid
memory". Is this reasonable to ask for 3/3 for my answer?




首先,值得指出(!)这不是任何种类

官方标准C ++术语。也就是说,你只回答

布置了一种类型的无效内存,但它甚至可以包括程序中的
内存等等。所以,如果你有2/3,快乐。

-

Greg Comeau /庆祝20年的Comeauity!

Comeau C / C ++ ONLINE = => http://www.comeaucomputing.com/tryitout

世界级编译器:令人惊叹的C ++,惊人的C99,很棒的C90。

Comeau C / C ++与Dinkumware的库...你试过吗?



First, it''s worth pointing(!) out that this is not any sort
of official Standard C++ term. That said, you''re answer only
laid out one type of invalid memory, but it could include even
memory that is in the program, etc. So, if you got 2/3, be happy.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware''s Libraries... Have you tried it?


在文章< di ********** @ panix2.panix.com>,

Greg Comeau< co **** @ comeaucomputing.com>写道:
In article <di**********@panix2.panix.com>,
Greg Comeau <co****@comeaucomputing.com> wrote:
在文章< 11 ********************** @ g14g2000cwa.googlegroups .com>,
__PPS__ < I - ********* @ yandex.ru>写道:
In article <11**********************@g14g2000cwa.googlegroups .com>,
__PPS__ <i-*********@yandex.ru> wrote:
在测验中我有一个关于悬挂指针的问题:
多么悬垂的指针和使用它的危险

我的回答是:
悬挂指针是一个指向某个ram区域的指针,它不是程序保留的。通过这样的指针访问内存可能会导致核心转储(内存访问违规)

这是10分钟测验中的两个问题之一(我迟到了5分钟)
这个测验:)

这个问题基于3标记,我得到2这个问题和
纠正是悬挂prt指针..指向无效的内存请问3/3我的答案是否合理?
in a quiz I had a question about dangling pointer:
"What a dangling pointer is and the danger of using it"

My answer was:
"dangling pointer is a pointer that points to some area of ram that''s
not reserved by the program. Accessing memory through such pointer is
likely to result in core dump (memory access violation)"

This was one of the two questions in a 10-min quiz (I was 5 mins late
for this quiz :)

This question is marked based on 3, I got 2 for this question and
correction was that dangling prt is pointer that "..points to invalid
memory". Is this reasonable to ask for 3/3 for my answer?



首先,值得指出(!)这不是官方标准的任何类型C ++术语。也就是说,你只回答了一种类型的无效记忆,但它甚至可以包括程序中的内存等等。所以,如果你有2/3,那就快乐吧。



First, it''s worth pointing(!) out that this is not any sort
of official Standard C++ term. That said, you''re answer only
laid out one type of invalid memory, but it could include even
memory that is in the program, etc. So, if you got 2/3, be happy.




顺便说一句,通常对于指向悬挂的指针,它通常会指向有效内存的
。请注意,有效内存不仅是程序有效访问的内存,而且还是指针以前有效访问的
。例如,

new或malloc的返回值,但后来删除了'

或freeed()。因此指针被称为悬挂,因为它不需要重置为有效的或有意无效的东西(例如空指针的b / b
)。这些年来似乎已经混淆了

包括任何无效指针,即使是没有悬空的。

-

Greg Comeau /庆祝20年的Comeauity!

Comeau C / C ++ ONLINE ==> http://www.comeaucomputing.com/tryitout

世界级编译器:令人惊叹的C ++,惊人的C99,很棒的C90。

Comeau C / C ++与Dinkumware的库...你试过吗?



BTW, normally for a pointer to dangle, it normally would have
previously pointed to valid memory. Note that valid memory is
not only memory that the program has valid access to but also
that the pointer previously had valid access to. For instance,
the return value of new, or malloc, but which was then delete''d,
or freed(). And hence the pointer is said to "dangle", since it
need not be reset to something valid, or purposely invalid (like
the null pointer). It seems to have muddled over the years to
include "any invalid pointer", even ones not dangling.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware''s Libraries... Have you tried it?


* Greg Comeau:
* Greg Comeau:

不需要重置为有效或有意无效的东西(如空指针)。

need not be reset to something valid, or purposely invalid (like
the null pointer).



好​​吧,空指针肯定对于复制

指针值并将其与其他指针值wrt进行比较有效。平等。


不幸的是,标准没有完全定义无效和有效的术语

指针,只给出一个无效的例子(指向已解除分配的

存储),并模糊地暗示另一个(不确定的指针值)。


作为工作定义,我更喜欢将nullpointer视为有效指针

(以及例如指向数组的一个过去结束的指针),因为这样可以简单地说_n $使用无效指针 - 可能! -

未定义的行为(如果标准清楚会很好)。对于

种类的指针,这个定义说的是有效的指针,那么你可以做什么级别:没有解除引用(nullpointer),取消引用但不做

任何需要一个实际对象的东西(一个过去的数组末尾,被破坏但是

没有解除分配的对象,零大小的新数组),通过相等而不是

否则当使用内置运算符(指向单个对象的指针)时,等等。


如果我们需要指向实际指向的指针的通用术语一个可用的

对象 - 据我所知,它没有任何术语,它肯定不是一般有效性所涵盖的b $ b ...我建议我们打电话他们是RealGood指针。

然后那些不是RealGood的是Un-RealGood或URG指针。 ;-)

URG指针可以有效或无效,如果它无效,所有用途都是

(可能!)未定义的行为。


否则就必须进入有效的灰色区域。


-

A:因为它搞砸了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

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



Well, the null pointer is certainly valid for the purposes of copying the
pointer value and comparing it to other pointer values wrt. equality.

Unfortunately the standard does not fully define the terms invalid and valid
for pointers, giving only one example of invalid (pointing to deallocated
storage), and vaguely implying another (indeterminate pointer value).

As a working definition I prefer to consider the nullpointer a valid pointer
(as well as e.g. pointer to one past end of array), because that way one can
say simply that _any_ use of an invalid pointer is -- probably! --
Undefined Behavior (it would be nice if the standard was clear). For the
kinds of pointer this definition says are valid pointers there are then levels
of what you can do: no dereferencing (nullpointer), dereference but don''t do
anything that requires an actual object (one past end of array, destroyed but
not deallocated object, zero size new''ed array), compare by equality but not
otherwise when using built-in operators (pointer to single object), and so on.

If we need a general term for a pointer that actually points to a useable
object -- and there is no term for it as far as I know, it certainly isn''t
covered by general validity -- I propose we call them RealGood pointers.
Then those that are not RealGood are Un-RealGood, or URG, pointers. ;-) An
URG pointer can be valid or invalid, and if it''s invalid, all uses are
(probably!) Undefined Behavior.

Otherwise one would have to get into gray-zones of validity.

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


这篇关于悬垂指针测验问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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