Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!DKAUNI2.BITNET!UK4H From: UK4H@DKAUNI2.BITNET ("JAE ", Juergen A. Erhard) Newsgroups: comp.lang.modula2 Subject: Re: Clever way to deal with this? Message-ID: <"90-02-12-20:09:32.76*UK4H"@DKAUNI2.BITNET> Date: 12 Feb 90 20:16:07 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Modula2 List Organization: The Internet Lines: 60 X-Unparsable-Date: Mon, 12 Feb 90 20:09:00 LCL mark wrote: { lines DO taste fine, ya know. } > I have a data structure consisting of a cardinal value followed by a > variable number of characters. The cardinal indicates how many characters > follow. > > How would you express this in Modula-2? How DO you express that in, say, C. Or some other language (not a 4GL, OC) What I like to know is: Are you porting a program from another language to M2, or did you devise such a struct out of thin air? Anyway you want it, M2 is not the ideal language for such a struct. Some way (a kludge, to be honest) would be: type mytype=record numOfChars:CARDINAL; chars:POINTER TO ARRAY <0..Max> OF CHAR; end; Two notes: 1. The idea behind the whole thing is to Storage.ALLOCATE() (or some such) as much memory as needed to hold all chars. This would mean you have to do all ALLOCATE'ING/DEALLOCATE'ING by 'hand'. 2. Set square brackets for < and > (I'm sittin' in front of a grubby old IBM 3278 (sucks!), and it doesn't give me no squares...) Also set Max and mytype to your choice... Another way (but still kludge, and in some way more, in another less awkward than the first) type mytype2=record numOfChars:CARDINAL; chars:ARRAY <0..Max> OF CHAR; end; Again, replace <,> and Max, mytype2... Note: This needs no great care, BUT (there's always a BUT to everything, it seems) it needs the same fixed amount of storage all the time, no matter how much of it is used. Of course, the latter is more of a kludge: it's nonsense. Except if you absolutely need it (some OS'es are sooo demanding...). Why? Well, M2 has (limited...) support for strings. But you can look up the string support of M2 in any good M2 reference... (guess I wasted enough net bandwidth already...) > mark > ------- > Internet: mark@mamab.FIDONET.ORG > UUCP: uunet!tarpit!libcmp!mamab!mark > Fidonet: mark at 1:363/9.0 -jae ======================================================================== Juergen A. Erhard eMail: uk4h@dkauni2.bitnet phone: (+49) 721/591602 "You know that it's monday when you wake up and it's tuesday." Garfield DISCLAIMER: none, I don't speak legalese.