Re: [ooc-compiler] Unsafe pointers on the stack
Brought to you by:
mva
|
From: Stewart G. <sgr...@ii...> - 2005-05-26 01:14:34
|
Hi August,
> If I compile and run the following program I get a segmentation fault
> rather that a run time exception.
>
> MODULE Test;
> PROCEDURE P;
> VAR p: POINTER TO ARRAY OF LONGINT;
> BEGIN
> p[0] := 1
> END P;
> BEGIN
> P
> END Test.
>
> So in this regard the above program compiled with OOC is just as
> unsafe as a C program. Wasn't the elimination of wild pointers one of
> the design criteria of Oberon?
OOC generates the following warning for this code.
In file src/Test.Mod:
PROCEDURE P;
VAR p: POINTER TO ARRAY OF LONGINT;
BEGIN
p[0] := 1
#--------^
# 5: Warning: Undefined variable
END P;
BEGIN
P
OOC V1 used to support the optional initialisation of stack-based
variables (obviously, with a performance cost) via the "Initialize :=
TRUE" pragma. I'm not sure if this feature made it into the V2
compiler. Generally, if you check the compiler warnings it will pick up
most of these cases.
Cheers,
Stewart
|