[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] Re: double free or corruption with pointers
From: |
Dragiša Durić |
Subject: |
Re: [Gm2] Re: double free or corruption with pointers |
Date: |
Mon, 02 Aug 2010 12:04:05 +0200 |
Program compiles for me - 0.92 here, Fedora 12 x86_64.
On Sun, 2010-08-01 at 12:05 +0200, Martin Kalbfuß wrote:
> MODULE test2;
>
> IMPORT SYSTEM, SWholeIO, STextIO;
> FROM Storage IMPORT ALLOCATE, DEALLOCATE;
>
> TYPE DynArray = POINTER TO INTEGER;
> VAR myArray : DynArray;
> elementPtr : DynArray;
> BEGIN
> NEW(myArray, 6, 6);
> elementPtr := SYSTEM.ADDADR(myArray, 2*5+3);
> elementPtr^ := 5;
> SWholeIO.WriteInt(elementPtr^, 1); STextIO.WriteLn();
> DISPOSE(myArray);
> END test2.
>
> Maybe I'm wrong about pointers. Isn't there a better way of using
> dynamic arrays? It's really a pain.
You probably are. Pointer arithmetic is not how you do things in
Modula-2.
--
Dragiša Durić <address@hidden>