Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!caen!ox.com!math.fu-berlin.de!unidui!unido!mcshh!janhh!jan From: jan@janhh.hanse.de (Jan Willamowius) Newsgroups: comp.lang.modula2 Subject: How to write NEW? Message-ID: <5122672@janhh.hanse.de> Date: 19 Apr 91 14:22:24 GMT Organization: janhh, Atari UUCP server, Hamburg Lines: 46 It looks like Wirth is using different ways to allocate memory in different versions of his books. Sometimes he uses 'Allocate(Var,SIZE(Type)' and sometimes 'NEW(Var)'. I like the second way better, but my compiler only supports Allocate. So, is there a way to write a NEW (and DISPOSE, of course) ? This is how far I got: --- DEF --- DEFINITION MODULE Storage; FROM Heap IMPORT Allocate, Deallocate; FROM SYSTEM IMPORT ADDRESS; PROCEDURE NEW(VAR p : ADDRESS); PROCEDURE DISPOSE(VAR p : ADDRESS); END Storage. --- IMP -- IMPLEMENTATION MODULE Storage; FROM Heap IMPORT Allocate, Deallocate; FROM SYSTEM IMPORT ADDRESS; PROCEDURE NEW(VAR p : ADDRESS); BEGIN Allocate(p,SIZE(p^)); END NEW; PROCEDURE DISPOSE(VAR p : ADDRESS); BEGIN Deallocate(p,SIZE(p^)); END DISPOSE; BEGIN END Storage. The problem is that p 'looses' its type in the conversion to ADDRESS and only a WORD is Allocated (ADDRESS is POINTER TO WORD). Any ideas ? Greetings, Jan -- Jan Willamowius, Nienredder 6, 2000 Hamburg 54, Germany E-Mail: jan@janhh.hanse.de