Assigning class to pointer and back is that safe ?

From: Skybuck Flying (nospam_at_hotmail.com)
Date: 02/19/04


Date: Thu, 19 Feb 2004 04:31:16 +0100

Hi,

var
p : pointer;
c : TsomeClass;

begin
   c := TsomeClass.Create;
   p := c;
end;

later:

begin
    c := p;
    c.destroy;
end;

So this code creates a class assigns it to a pointer... c goes out of scope,
p is remember.

Then later p is assigned back to a c variable... then c is used to destroy
the class.

Is this safe ?

So in fact this code is assigning a class reference to a pointer and back is
that safe ?

Bye,
  Skybuck.



Relevant Pages

  • Safe pointer arithmetic and typecasts :D
    ... I always wondered how to do safe pointer aritmetic in delphi without ... overflow errors or warnings... ... With Pchar is probably safest. ...
    (alt.comp.lang.borland-delphi)
  • Re: is it safe to zero float array with memset?
    ... >> Not if you then try to use the value as a float or as a pointer. ... >> load it into an address register (no dereference needed). ... If it's a matter of the implementation itself, *IT'S NOT SAFE*. ...
    (comp.lang.c)
  • Re: The meaning of populated.
    ... in Perl you convert the list to a ... scalar] and get 0, or else you examine the ... pointer to its head and learn that it's a null pointer. ... (Sometimes it is safe, if you're really really sure that the ...
    (alt.usage.english)
  • Re: WM_SETTEXT with Subclassed CEdit: Is this safe?
    ... No I don't think that is safe... ... outside code called and you have no idea what that pointer is, readonly, ... control what to display, not asking your control to copy over a buffer. ... > stores units for each field. ...
    (microsoft.public.vc.mfc)
  • Re: Fix UDF-FS potentially dereferencing null
    ... Hey, "sparse" is some way away from actually generating code, so I don't ... right now it is an attribute on the "pointer", ... so it's not like the back-end doesn't see that part - it's assigning ... from a non-safe pointer to a safe one _after_ doing the test on the ...
    (Linux-Kernel)