comp.lang.ada
 help / color / mirror / Atom feed
* Dangling pointer?
@ 1996-04-16  0:00 chen
  1996-04-16  0:00 ` Robert A Duff
  1996-04-19  0:00 ` Todd Coniam
  0 siblings, 2 replies; 3+ messages in thread
From: chen @ 1996-04-16  0:00 UTC (permalink / raw)



    What is "dangling pointer",can someone give me a defination and example?
Please e-mail me kc44097@huey.csun.edu

                Thankx




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Dangling pointer?
  1996-04-16  0:00 Dangling pointer? chen
@ 1996-04-16  0:00 ` Robert A Duff
  1996-04-19  0:00 ` Todd Coniam
  1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 1996-04-16  0:00 UTC (permalink / raw)


In article <4l0r36$jte@dewey.csun.edu>, chen <kc44097@csun.edu> wrote:
>
>    What is "dangling pointer",can someone give me a defination and example?
>Please e-mail me kc44097@huey.csun.edu

A dangling pointer is a pointer that points to something that no longer
exists, or is invalid in some way.  For example:

    X: Some_Pointer := new Whatever;
    Y: Some_Pointer := X;
    ...
    Free(Y);
    ... -- Now, X is a dangling pointer, and you better not say X.all.

You can also create dangling pointers by using the 'Unchecked_Access
attribute to create a pointer to a local variable, and save that pointer
in a global.  When the procedure is left, the global contains a dangling
pointer.

In general, in Ada, dereferencing dangling errors is not detected -- you
won't usually get a sensible error message, but your program may go
haywire.

According to the RM, it's not a bug to create dangling pointers.  It's a
bug to deference them.

- Bob




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Dangling pointer?
  1996-04-16  0:00 Dangling pointer? chen
  1996-04-16  0:00 ` Robert A Duff
@ 1996-04-19  0:00 ` Todd Coniam
  1 sibling, 0 replies; 3+ messages in thread
From: Todd Coniam @ 1996-04-19  0:00 UTC (permalink / raw)


In article <4l0r36$jte@dewey.csun.edu>, kc44097@csun.edu says...
>
>
>    What is "dangling pointer",can someone give me a defination and example?
>Please e-mail me kc44097@huey.csun.edu
>
>                Thankx

-- 

A dangling pointer occurs when you:
1. create an object
2. reference it with a pointer (access type)
3. destroy the original object
   (the pointer is now pointing to deallocated memory)

If you try to reference the (now deallocated) original object you are using a 
dangling pointer and nothing can be guarenteed about what you'll get.
Often you get the original contents.  Your best case is an exception, but any 
implementation could cause all kinds of errors.
	
-------------------------------------------------------------------------
Todd Coniam       | Member: Team Ada
tconiam@ionet.net | Ada 95 - The international standard in OO languages
-------------------------------------------------------------------------
Check: http://lglwww.epfl.ch/Ada/     Free compiler: http://www.gnat.com/





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-04-19  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-16  0:00 Dangling pointer? chen
1996-04-16  0:00 ` Robert A Duff
1996-04-19  0:00 ` Todd Coniam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox