gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] Dynamic arrays?!?


From: Andreas Fischlin
Subject: Re: [Gm2] Dynamic arrays?!?
Date: Sat, 19 Sep 2009 16:47:52 +0200
User-agent: Thunderbird 2.0.0.23 (Macintosh/20090812)

Why programing C style when you have Modula-2?  ;-)

Andreas


Gaius Mulley wrote:
Martin Kalbfuß <address@hidden> writes:

  
I'm a bit confused. You're talking about multidimensional dynamic arrays
in the news. I don't get even a simple dynamic array working.

    

Hi Martin,

multidimensional dynamic array _parameters_ as per ISO.  PIM[234]
defined the behaviour of uni dimensional dynamic array parameters.
So you can now:

PROCEDURE foo (a: ARRAY OF CHAR) ;
VAR
   h: CARDINAL ;
BEGIN
   h := HIGH(a)
END foo ;


as well as:

PROCEDURE bar (a: ARRAY OF ARRAY OF CHAR) ;
VAR
   h: CARDINAL ;
BEGIN
   h := HIGH(a[0])
END bar ;

  
What's the way to go? ALLOCATE and pointer arithmetic? Or is there
anything I missed? The resources on the net wasn't very helpfull at all.
    

yes this is probably the way to go if you want the equivalent of the GNU C
constructs:

   char a[n];

or in C (without GNU extensions)

   char *a = (char *)alloca(n);

then the equivalent in Modula-2 might be:

VAR
   a: POINTER TO CHAR ;
BEGIN
   ALLOCATE(a, n) ;
   ...

   DEALLOCATE(a, n)
END

and you would have to manage the array arithmetic yourself though..

regards,
Gaius


_______________________________________________
gm2 mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/gm2
  

--
________________________________________________________________________
ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND

address@hidden
www.sysecol.ethz.ch/staff/af

+41 44 633-6090 phone
+41 44 633-1136 fax

Make it as simple as possible, but distrust it!
________________________________________________________________________
 

Attachment: andreas_fischlin.vcf
Description: Vcard


reply via email to

[Prev in Thread] Current Thread [Next in Thread]