🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4936

Re: Clever way to deal with this?

#4936
From: Stephen Wilson Bailey
Date: Mon, 12 Feb 1990 22:58
42 lines
1385 bytes
TYPE
  BufType = RECORD
    length: CARDINAL;
    data: ARRAY [0..MAX(CARDINAL)] OF CHAR;
  END;
  BufPtrType = POINTER TO BufType;

VAR
  mybuf: BufPtrType;

(*
 * Somewhere in this code you either malloc
 *  the buffer, or cast something to it.
 *)
    .
    .
    .
  PrintBuffer(mybuf);
    .
    .
    .

PROCEDURE PrintBuffer(bptr: BufPtrType);
VAR curchar: CARDINAL;
BEGIN
  FOR curchar := 0 TO bptr^.length DO
    Write(bptr^.data[i]);
  END;
END;


--------------------------------------
If you don't trust your compiler to optimize away the
de-reference, using ``WITH bptr^ DO'' will usually
force the issue ('though not always.  Personally, I leave it
up to the compiler).

You're right, it isn't handled as well as it could be.
The WRL Modula-2 includes a ``flexible array'' extension for
just this purpose.  I assume Modula-3 has a comparable notion.

Steph
Technical Details
Message-ID: <9002122258.AA07744@candide>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!GARGOYLE.UCHICAGO.EDU!bailey%candide

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!GARGOYLE.UCHICAGO.EDU!bailey%candide
From: bailey%candide@GARGOYLE.UCHICAGO.EDU (Stephen Wilson Bailey)
Newsgroups: comp.lang.modula2
Subject: Re: Clever way to deal with this?
Message-ID: <9002122258.AA07744@candide>
Date: 12 Feb 90 22:58:42 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Reply-To: Modula2 List <INFO-M2%UCF1VM.BITNET@PSUVM.PSU.EDU>
Organization: The Internet
Lines: 42