Discussion:
Storing a pointer to a record on stack to heap...
(too old to reply)
Kim, DoHyung
2004-06-24 19:01:12 UTC
Permalink
Hello,

I'm relatively new to Oberon-2 and Component Pascal. While I'm playing
with them, I found that the following is possible with them while it
shouldn't.
Below, I declared a record on stack and passed its pointer to a global
variable. And then called a method on the stored pointer after the
stack frame where the record is allocated disappears.

Is this a well known feature of Oberon-2 and Component Pascal?
I think this kind of thing should not be possible if they are aiming a
robust, type-safe language.

Thanks in advance.

DoHyung

@ I'm investigating on them to see whether they are appropriate for
the development of my company's product. Though I'm sure they are far
better than C and complex C++ thing, just hope to check whether
there's any pitfall.


MODULE test;
IMPORT CPmain;

TYPE
R0 = RECORD i: INTEGER END; P0 = POINTER TO R0;

VAR
global: P0;

PROCEDURE (p: P0) Proc1, NEW;
BEGIN
global := p
END Proc1;

PROCEDURE (VAR r: R0) Proc2, NEW;
BEGIN
END Proc2;

PROCEDURE call;
VAR
r: R0;

BEGIN
r.Proc1;
global.Proc2;
END call;

BEGIN
call
END test.
Chris Burrows
2004-06-25 02:21:32 UTC
Permalink
Post by Kim, DoHyung
I'm relatively new to Oberon-2 and Component Pascal. While I'm playing
with them, I found that the following is possible with them while it
shouldn't.
Below, I declared a record on stack and passed its pointer to a global
variable. And then called a method on the stored pointer after the
stack frame where the record is allocated disappears.
Is this a well known feature of Oberon-2 and Component Pascal?
I think this kind of thing should not be possible if they are aiming a
robust, type-safe language.
This looks like it might just be a bug in the Gardens Point implementation
of Component Pascal rather than a 'feature' of the language itself.

If you try to compile a similar example using Oberon Microsystems Blackbox
implementation of Component Pascal (which you can download from
http://www.oberon.ch/blackbox.html ) it will give you a compile-time error.

For more specific information on this and similar problems that you may
encounter with GPCP, submit your query to GPCP support at the email address
given for reporting bugs in the GPCP Getting Started notes. I have found
them to be very responsive to similar queries.

Alternatively, post them in the GPCP discussion group at:

http://groups.yahoo.com/group/GPCP/

Chris Burrows
CFB Software
http://www.cfbsoftware.com

Loading...